1

I am trying to automate this process.

step 1: change system date to a specific date.

step 2: open an application.

step 3: change system date back to normal.

Now on Automator, I have three apple scripts placed like this.

enter image description here

on run {input, parameters}

tell application "Terminal"
    do script with command "sudo date 082704002018"
    activate
end tell

delay 1
tell application "System Events"

    keystroke "mypassword" & return
    delay 3

end tell

end run

on run {input, parameters}

tell application "Terminal"
    do script with command "open -a applicationName"
    activate
end tell

end run

on run {input, parameters}

tell application "Terminal"
    do script with command "sudo ntpdate -u time.apple.com"
    activate
end tell

delay 1
tell application "System Events"

    keystroke "mypassword" & return
    delay 3

end tell

end run

The problem is that Automator only runs the first code. I'm not sure how to make it run all the codes in order.

Sorry if this is a stupid question. I am completely new to automator and applescript.

Thank you

1 Answer 1

1

I'm not quite sure why you chose to use three separate AppleScripts. You can combine them all into one AppleScript as I have done in this following example. I'm not quite sure why you used the “activate” commands. I don't think they are necessary so I removed those lines of the code. Anyway, this following code should work for you…

tell application "Terminal"
    do script with command "sudo date 082704002018"
end tell
delay 1
tell application "System Events"
    keystroke "mypassword" & return
    delay 3
end tell
tell application "Terminal"
    do script with command "open -a applicationName"
    delay 1
    do script with command "sudo ntpdate -u time.apple.com"
end tell
delay 1
tell application "System Events"
    keystroke "mypassword" & return
    delay 3
end tell

Alternately, launching Terminal app to run shell scripts is not necessary all the time as you can run shell scripts in AppleScript by using the “do shell script” command. This following applescript code is your code using only eight lines of code.

do shell script "sudo date 082704002018"
tell application "System Events" to keystroke "mypassword" & return
delay 3
do shell script "open -a applicationName"
delay 1
do shell script "sudo ntpdate -u time.apple.com"
delay 1
tell application "System Events" to keystroke "mypassword" & return

If my versions of your code throw errors, it may be necessary to adjust the delay commands or re-insert the activate commands

If you are hell-bent on using your version of the code and three separate Applescripts, just remove the on run {input, parameters} and end run lines of code from each AppleScript and that should eliminate your problem

Sign up to request clarification or add additional context in comments.

1 Comment

Did you test your code ? I haven't, but I can already see that your last code block will not work. do shell script launches a shell process without a terminal, so it can't receive user input. Therefore, keystroking the password will be pointless.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.