简体   繁体   中英

Applescript to change shortcut to be able to clear lines in iTerm2

I am trying to make an applescript to be able to cmd + L to get ctrl + L to clear lines in iTerm as suggested by this answer .

After copying a working, example applescript from here shown below,

tell application "System Events" to keystroke "l" using control down

I am trying to change the application to "iTerm2" as shown below,

tell application "iTerm2" to keystroke "l" using control down

so the shortcut in not global, but I get a Syntax error:

A identifier can't go after this “"”.

Removing the quotes ( this also works in the working example ) brings up a different Syntax error:

"A identifier can't go after this identifier."

What am I doing wrong?

Thanks to @gurkensaas's comment for the correct answer. I post the complete working script below for other people.

tell application "iTerm" to activate
delay 0.1
tell application "System Events"
    try
        keystroke "l" using control down
    end try
end tell

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM