1

I'm struggling to get a basic AppleScript script running correctly. Here is what I want to do:

User highlights text, shortcut key is pressed and then AppleScript will copy the selected text and type something before it and something after it.

Here is the script I have, it doesn't seem to execute correctly, anyone have an idea why?

on run
    tell application "System Events"
        keystroke "c" using command down
        keystroke "<answer>"
        keystroke "v" using command down
        keystroke "</answer>"
    end tell
end run
  • Sorry to ask this, but can you please mark the question as answered? I want to put a bounty on a question I have and need the points. Thanks. – MBUST May 15 '18 at 10:27
1

This might do the trick:

on run
    tell application "System Events"
        keystroke "c" using command down
    end tell

    tell application "Finder"
        set x to the clipboard
        set x to "Today " & x & " a sunny day"
        set the clipboard to x
    end tell

    tell application "System Events"
        keystroke "v" using command down
    end tell
end run

Though it might be better to write the script without using the clipboard (i.e., without copying and pasting), but that requires involvement of the application(s) you are working with, and you did not tell us which ones they are.

You must log in to answer this question.

protected by Community May 1 '18 at 15:19

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged .