MacOS command line tool which executes OSA scripts (AppleScript, JavaScript, etc.)
Questions tagged [osascript]
267 questions
56
votes
7 answers
How to check in AppleScript if an app is running, without launching it - via osascript utility
Consider the following AppleScript:
on is_running(appName)
tell application "System Events" to (name of processes) contains appName
end is_running
set safRunning to is_running("Safari")
if safRunning then
tell application "Safari"
--…

gimboland
- 1,926
- 2
- 19
- 28
21
votes
2 answers
osascript using bash variable with a space
I am using osascript in Bash to display a message in Notification Center (Mac OS X) via Apple Script. I am trying to pass a text variable from Bash to the script. For a variable without spaces, this works just fine, but not for one with…

Bernd
- 675
- 3
- 13
- 23
18
votes
2 answers
osascript / syntax error: Expected end of line but found command name. (-2741)
I'm running into problems with a shell script that utilizes a small portion of Applescript. When I compile it with Applescript editor it works. It does not though within a shell script.
44:49: syntax error: Expected end of line but found command…

dr. null
- 197
- 1
- 2
- 7
13
votes
2 answers
How do I simulate a mouse click through the mac terminal?
Is there any way to do this without any programs or scripts? (Maybe through osascript?)

chesspro
- 131
- 1
- 1
- 4
13
votes
6 answers
Applescript (osascript): opening split panes in iTerm 2 and performing commands
The following works to open two tabs in iTerm 2.
I can't seem to figure out how to get this to using split panes instead.
I've tried applying what I see on several forums, but it never works. Could someone point me in the right direction?
osascript…

Joel
- 665
- 2
- 9
- 23
12
votes
3 answers
Applescript–execute multi line code
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.

Cplusplusplus
- 337
- 1
- 3
- 16
11
votes
2 answers
Pass in variable from shell script to applescript
I've got a shell script that I call that uses osascript, and that osascript calls a shell script and passes in a variable that I've set in the original shell script. I don't know how to pass that variable in from the applescript to shell…

SirRupertIII
- 12,324
- 20
- 72
- 121
9
votes
2 answers
Send group iMessage using applescript
Does anyone know how to send a group message using applescript/osascript? I've tried a bunch of stuff but nothing seems to work.

Cody C
- 3,087
- 4
- 24
- 32
8
votes
4 answers
What is a good VM for developing a hobby language?
I'm thinking about writing my own little language.
I found a few options, but feel free to suggest more.
JVM
Parrot
OSA
A lot of languages are using the JVM, but unless you write a Java-ish language, all the power the stdlib gives you is going to…

Pepijn
- 4,145
- 5
- 36
- 64
8
votes
2 answers
Combining variables in Bash to form a command sent to AppleScript using the osascript command
I'm trying to make this script work. It's a Bash script that is meant to take some variables, put them together and use the result to send an AppleScript command. Manually pasting the string echoed from the variable to_osa behind osascript -e to the…
user912475
8
votes
1 answer
Mac - List opened windows in terminal
I want to list opened windows in the terminal to get x, y, width and height like xwininfo -root -tree for X11.
I tried:
osacript -e tell application "Microsoft Word" to get the bounds of the front window
But it's does not work for all Application…

Tokytok
- 298
- 2
- 6
- 14
7
votes
1 answer
Strange error running osascript -e [command] on macOS Mojave
I've just done a clean install of macOS Mojave (albeit various bits and pieces reinstalled) and getting a strange error running a bash script which in turn runs AppleScript via osascript. Any command passed to osascript -e seems to produce the same…

Claire Furney
- 2,115
- 3
- 24
- 36
7
votes
7 answers
How to get POSIX path of the current script's folder in JavaScript for Automation?
In AppleScript it’s possible to get the the POSIX path of the folder the current script is located in using this line:
POSIX path of ((path to me as text) & "::")
Example result: /Users/aaron/Git/test/
What’s the JavaScript equivalent?

aaronk6
- 2,701
- 1
- 19
- 28
6
votes
3 answers
Mac: Getting path of current desktop picture from terminal
I'm writing a bash script that takes care of setting the desktop background on my mac. I can set the desktop background with:
$ osascript -e 'tell app "Finder" to set desktop picture to POSIX file "/Library/Desktop Pictures/Solid Colors/Solid…
user4434778
6
votes
1 answer
How to hide a password from a prompted osascript dialogue from a Mac/UNIX Shell Script
I'm in the final phase of designing a script to automate my Active Directory binding that will be used by multiple people. Because of this, I need to prompt for a user name and password. I've successfully created the prompt, but want to find some…

ghostof101
- 187
- 1
- 9