0

I am using applescript on Mac OS X 10.10 (Yosemite). I notice that the keystroke action tends to be much slower than 10.9.

Below is my applescript, which tells Terminal to input "cd my current path in Finder" and press return:

tell application "Finder"
    try
        set currentFolder to (folder of the front window)
        set currentPath to (POSIX path of (target of the front window as alias))
    on error
        set currentFolder to desktop
        set currentPath to (POSIX path of (desktop as alias))
    end try
end tell

tell application "Terminal"
    activate
    delay 0.5
    tell application "System Events"
        set cdtocurrentPath to "cd \"" & currentPath & "\"" as string
        keystroke cdtocurrentPath
        keystroke return
    end tell
end tell

Previously, in OS X 10.9, the keystroke for inputting the current path is very fast (less than 1s for a long string). However, in 10.10, it tends to be very slow (usually more than 3-4s) such that I can clearly watching the letters being typed.

Besides, other actions in System Events are also slower than 10.9 and hence I have to increase the time for delay to make them work properly.

Could anyone possibly explain this? Or give an alternative solution? Thanks!

sophon
  • 1
  • 2

1 Answers1

0

I've tested it in Script Editor on 10.10 and it runs in less than 1s. There must be some other issue.

It might help to use the do script command:

tell application "Terminal" to do script "cd \"" & currentPath & "\""
user309603
  • 1,518
  • 11
  • 10
  • Thank you for your awesome solution! I modified it to `tell application "Terminal" to do script "cd \"" & currentPath & "\"" in window 1` to achieve my requirement. – sophon Oct 27 '14 at 15:35