6

In Automator, there is a way to quickly convert an Action into its equivalent Applescript in Automator, I think by dragging it in some tricky way. I saw this some time ago but have now forgotten. I've tried searching and can't find it.

  • Probably because it's not possible. AppleScript commands and Automator actions are different, some app may support one while not the other. Both are to do repetitive tasks, but different. – user14492 Sep 28 '15 at 17:59
9

In case anyone has this question, I found it, but it only works for recorded actions.

After you Record some clicks or other actions in Automator, they appear in a "Watch Me Do" action. You can then click on and drag an individual action out of that Action and release when the + sign appears. Automator will add a "Run AppleScript" action with the AppleScript that sends the same clicks and key presses to System Events.

You can also simply Copy the action you want, switch over to AppleScript Editor, and paste to get the same code.

Example: "Click Skype in the Dock" Event converts to the following AppleScript:

on run {input, parameters}
    -- Click “Skype” in the Dock.
    delay 7.872251
    set timeoutSeconds to 2.000000
    set uiScript to "click UI Element \"Skype\" of list 1 of application process \"Dock\""
    my doWithTimeout( uiScript, timeoutSeconds )
    return input
end run

on doWithTimeout(uiScript, timeoutSeconds)
    set endDate to (current date) + timeoutSeconds
    repeat
        try
            run script "tell application \"System Events\"
" & uiScript & "
end tell"
            exit repeat
        on error errorMessage
            if ((current date) > endDate) then
                error "Can not " & uiScript
            end if
        end try
    end repeat
end doWithTimeout

How to convert recorded events in Automator:

Click and event and drag to create a new action Automator converts the event to Applescript

  • I up voted this on its merits of how you gather AppleScript code from a Watch Me Do action however you said "You can also simply Copy the action you want, switch over to AppleScript Editor, and paste to get the same code." and while this might be true in some cases nonetheless it's not true in some cases as the AppleScript Code cannot always be copied exactly from Automator in this manner to AppleScript Editor and run successfully without modifying the code. – user3439894 Jan 12 '17 at 11:56
0

It's impossible. You can do similar actions in applescript, but there is no way to convert an existing automator script to applescript.

  • Might be generally true (I don't know), but it is possible for the recorded actions ("Watch Me Do") - see my solution below. – Nate Jan 12 '17 at 2:48
0

Create your Automator file as an "Application" type.

Tell your AppleScript to run your Automator app.

Something like:

open "/Users/george/AutomatorFiles/MyScript.app"

Works for me!

  • That's useful too, though not quite what I was looking for, which was to see the code so I can understand and reuse it. – Nate Jan 12 '17 at 2:47

You must log in to answer this question.

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