tell application "iTerm" to activate
delay 0.1
tell application "System Events" to tell process "iTerm"
keystroke "Lsj!"
end tell
I want know how can i get the right way to enter some character. keystroke command can't identify case.
This should work
set the clipboard to "Lsj!" as text
tell application "iTerm" to activate
delay 0.1
tell application "System Events" to tell process "iTerm"
keystroke (the clipboard)
end tell
wch1zpink's answer should work.
You can also write out the letters individually if needed
keystroke "l" using {shift down} -- uppercase
keystroke "sj!" -- lowercase
That should work
tell application "iTerm" to activate
delay 0.1
tell application "System Events" to tell process "iTerm"
key code 37 using {shift down}
key code 1
key code 38
end tell
Related
I am trying to send a keystroke (command+ shift+ r) to a macOS (Mojave) app called "Dbeaver" every minute as long as DBeaver is the active app. I have tried the following with no effect.
tell application "System Events"
set activeApp to name of first application process whose frontmost is true
if "DBeaver" is in activeApp then
tell application "System Events" to keystroke "r" using {command down, shift down}
end if
end tell
The script works perfectly fine if its simple like the following:
activate application "DBeaver"
tell application "System Events" to keystroke "r" using {command down, shift down}
I do not have the application you referred to but I tested this following AppleScript code using TextEdit.app and it worked. Let me know if you run into any errors or issues
tell application "System Events"
repeat while (exists of application process "DBeaver")
set activeApp to name of first application process whose frontmost is true
if "DBeaver" is in activeApp then
tell its application process "DBeaver"
repeat while frontmost
keystroke "r" using {command down, shift down}
delay 60
end repeat
end tell
end if
end repeat
end tell
You want to avoid using something like a repeat loop, as that will block the app's user interface (for quitting or to just avoid the spinning wheel of death). A relatively easy way to repeat stuff like that is to make a stay-open application, and put your repeating code in the idle handler, which uses a timer - for example:
on idle
tell application "System Events"
set activeApp to name of first application process whose frontmost is true
if "DBeaver" is in activeApp then
tell application "System Events" to keystroke "r" using {command down, shift down}
end if
end tell
return 60 -- do it again in 60 seconds
end
The statements in the idle handler are run when the app is idle; the return value determines the number of seconds before the handler is run again.
I have a problem with my application, I want AppleScript to type "date" in Terminal:
(
activate application "Terminal"
tell application "System Events"
keystroke "date"
keystroke return
end tell
)
It works, but if the language of my keyboard is set to Russian, my app types "####" instead of "date". How to make AppleScript always use the English keyboard mapping?
If you have to send a string to the cursor/insertion point, you can avoid the keystroke command by storing the string on the clipboard and then pasting it.
tell application "Terminal" to activate
set theString to "date"
set the clipboard to theString
delay 0.1
tell application "System Events"
tell process "Terminal"
tell menu bar item "Edit" of menu bar 1
click menu item "Paste" of menu 1
end tell
end tell
end tell
delay 0.1
You should also explore sending a command to the terminal window as a command. Tell a Terminal window to do script.
tell application "Terminal"
activate
set thisWindow to do script "echo 'hello world'" in window 1
do script "echo 'goodbye all'" in thisWindow
end tell
You didn't give enough details of what you're doing to know how best to solve your problem.
I made a simple AppleScript that copies the layer names from Photoshop and pastes them into Illustrator. It worked fine in Mountain Lion but now it doesn't work properly in Yosemite. It repeats 6 times, but it doesn't seem to activate Illustrator on the first run through. It does activate Illustrator the other 5 times it repeats. Here it is:
repeat 6 times
tell application "Adobe Photoshop CC 2014" to activate
tell application "System Events"
tell process "Photoshop"
keystroke "/" using command down
keystroke "c" using command down
keystroke tab
end tell
end tell
delay 0.3
tell application "Adobe Illustrator" to activate
tell application "System Events"
tell process "Illustrator"
keystroke "v" using command down
keystroke return
keystroke "-"
keystroke space
end tell
end tell
end repeat
end
Thanks for any help!
tell application "System Events" to repeat 6 times
tell process "Photoshop" to repeat until frontmost is true
set frontmost to true
delay 1
end repeat
keystroke "/" using command down
keystroke "c" using command down
keystroke tab
tell process "Illustrator" to repeat until frontmost is true
set frontmost to true
delay 1
end repeat
keystroke "v" using command down
keystroke return
keystroke "-"
keystroke space
end repeat
I'm trying to write an Applescript in Automator that will press the left arrow button while holding down control, option, and command. The code I have so far is:
on run {input, parameters}
tell application "System Events"
tell application "Sublime Text 2" to activate
keystroke "left" using {control down, option down, command down}
end tell
return input
end run
However, this is not working. Any suggestions as to how to fix this code?
Thanks!
When using arrow keys you need to target them via key code.
tell application "Sublime Text 2" to activate
tell application "System Events"
key code 123 using {control down, option down, command down}
end tell
ARROW KEY CODES
LEFT: (key code 123)
RIGHT: key code 124)
UP: (key code 126)
DOWN: (key code 125)
You can use any ASCII code, for the arrow keys this will be:
tell application "System Events" to keystroke (ASCII character 31) --down arrow
tell application "System Events" to keystroke (ASCII character 30) --up arrow
tell application "System Events" to keystroke (ASCII character 29) --right arrow
tell application "System Events" to keystroke (ASCII character 28) --left arrow
Links:
Credits
ASCII CODES
I'm trying to automate opening and saving a file in applescript. I can't seem to get consistent results with the save dialog though. Is it possible to change a save dialog to a specific folder in applescript?
This might help you navigate to a folder once the save dialog is raised:
set the clipboard to "/path/to/your/folder"
tell application "System Events" to tell process "SketchUp" -- I'm guessing on SketchUp name
keystroke "G" using {command down, shift down}
delay 1
keystroke "v" using {command down}
delay 1
keystroke return
delay 1
keystroke return
delay 1
end tell
You can do it and keep your clipboard intact, I think. If your save dialog is in TextEdit, if you last saved something to the desktop, for example, the following would change your destination back to Documents. It's easier just to use ⌘+D for that, of course, but you can use substitute pretty much whatever path you need. If you have a path with a folder having non-AppleScript allowable characters in the path (such as quotes), you can escape each with the backslash ("\") character.
tell application "TextEdit"
activate
try
tell application "System Events"
keystroke "g" using {shift down, command down}
do shell script "sleep 0.2"
keystroke "~/Documents"
do shell script "sleep 0.2"
keystroke return
end tell
end try
end tell