I have some apple script code:
tell application "System Events"
key code 97
end tell
How do i write the code as a osascript -e
command in Terminal?
Everytime I try using \n
or the such, I get errors. Sorry if I'm not being specific enough.
You have a couple of options:
Pass each line of the AppleScript code as a separate -e option:
osascript -e 'tell application "System Events"' -e 'key code 97' -e 'end tell'
Pipe the AppleScript code to osascript's STDIN:
osascript <<END
tell application "System Events"
key code 97
end tell
END
Oh, and you can also save AppleScript code as an executable shell script. Just add #!/usr/bin/osascript
at the top of the code and save it as a plain text file:
#!/usr/bin/osascript
tell application "System Events"
key code 97
end tell