Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8434643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:42:47+00:00 2026-06-10T06:42:47+00:00

Is is possible to invoke a copy command (as if the user pressed Cmd

  • 0

Is is possible to invoke a copy command (as if the user pressed Cmd+C) from a bash script? Basically I want to write a simple script that I run with a global hotkey and it should take the current selection from the active app, replace something and paste the result. Is this possible?

The best I could come up so far is using pbpaste and pbcopy, but I’d like to automate that if possible.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T06:42:48+00:00Added an answer on June 10, 2026 at 6:42 am

    If you’re just trying to modify a text selection, you could use AppleScript.

    osascript -e 'try
        set old to the clipboard
    end try
    try
        delay 0.3
        tell application "System Events" to keystroke "c" using command down
        delay 0.2
        set text item delimiters to linefeed
        set input to (paragraphs of (the clipboard as text)) as text
        set the clipboard to do shell script "shopt -u xpg_echo; echo -n " & quoted form of input & " | rev" without altering line endings
        tell application "System Events" to keystroke "v" using command down
        delay 0.05
    end try
    try
        set the clipboard to old
    end try'
    

    The first delay is for releasing modifier keys if the script is run with a shortcut that has other modifier keys than command. The second delay could also be reduced to something like 0.05, but long selections or for example web views often need a longer delay. Without the third delay, the clipboard would sometimes be set to old before the text would get pasted.

    the clipboard as text and do shell script convert line endings to carriage returns by default. shopt -u xpg_echo is needed because the echo in sh interprets backslashes inside single quotes by default. If the input is longer than getconf ARG_MAX bytes, you can’t use echo and have to either write it to a temporary file or use pbpaste.

    pbpaste and pbcopy replace non-ASCII characters with question marks by default in the environment used by do shell script You can prevent that by setting LC_CTYPE to UTF-8.

    Telling System Events to click menu bar items would often be even slower, and it wouldn’t work in applications that don’t have a menu bar or in full screen windows.

    Another option would be to create an Automator service. But they also have small delays before they are run. There’s a bug where the shortcuts for services don’t always work until the services menu has been shown once on the menu bar. And the services aren’t available when the frontmost application doesn’t have a menu bar or a services menu.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to invoke ripple emulator from a custom made web app (ASP.NET
Is it possible to invoke Java EE web services from iPhone? and how?
Is it possible to invoke gnu parallel in a way that it would repeat
Is it possible to invoke a transactional method from within a Stateful EJB itself?
is it possible to invoke .jnlp file from java code? Example: Process p =
I guess it is not possible to invoke methods implemented in Scala traits from
Say I have class B derived from class A Is it possible to invoke
Is it possible to invoke method A.F() from instance of B class except of
Is it possible to invoke a function when a cron process is killed from
Possible Duplicate: Copy Constructor is not invoked # include <iostream> using namespace std; class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.