MacOS command line tool which executes OSA scripts (AppleScript, JavaScript, etc.)
Questions tagged [osascript]
267 questions
2
votes
1 answer
How to call a shell command from JavaScript JXA?
I have an AppleScript script that is calling a shell command that I want to convert to JavaScript (JXA) but I don't see the equivalent of do shell script.
Here is the script using AppleScript:
#!/usr/bin/osascript
on run argv
set…

1.21 gigawatts
- 16,517
- 32
- 123
- 231
2
votes
2 answers
Debugging osascript execution from within a ruby daemon
I have a need to frequently run an applescript on my web server. As the server is running rails, and I need access to my models before and after running the script, I thought that a daemon (via the daemons gem) might be appropriate.
In theory this…

Greg W
- 5,219
- 1
- 27
- 33
2
votes
2 answers
How do you run inline Applescript from a JXA/JavaScript for Automation script on macOS?
I have a script written in JavaScript which needs to run one small piece of AppleScript (to achieve some functionality I've been unable to implement due to a number of factors natively in JS).
It should be able to take a single string argument, and…

davemee
- 21
- 5
2
votes
3 answers
AppleScript to click Wi-Fi icon with option down
I would like to click on the Wi-Fi icon with the option key down to reveal extra options available on Mac. How can I automate it using AppleScript?
I tried using key down option and click menu item but no luck in revealing special options.
Is…

Giri Prasad
- 1,175
- 2
- 8
- 13
2
votes
1 answer
Bring window of process to the front?
This should be a simple enough question to answer (I assume).
Say I want to activate window 1 of process "ScreenFlow", how would I do this?
I do know that
Application('ScreenFlow').activate() brings Processes['ScreenFlow').windows[0] to the front.…

Sancarn
- 2,575
- 20
- 45
2
votes
1 answer
Send argument values to new terminal
I want to open new terminal and pass some values on OSX. I tried this code:
open_new_terminals_automatically()
{
osascript -e 'tell application "Terminal" to do script "cd $1; $2"'
}
# call the function and pass…

Peter Penzov
- 1,126
- 134
- 430
- 808
2
votes
1 answer
Macbook OpenEmu Python send keystrokes
I am really impressed by this MarlIO project and want to implement something similar using Python. However, I got the emulator OpenEmu working, however, I don't know how to control the game using Python.
Isn't it just a matter of sending a few…

B.Mr.W.
- 18,910
- 35
- 114
- 178
2
votes
0 answers
Matlab R2015a osascript on Mac OS X 10.9.5 -- communication between matlab sessions
I want to spawn a secondary matlab session to run a script programatically straight from the primary session.
I found out this may be possible using osascript as follows:
eval('!osascript -e ''tell application "Terminal"'' -e ''activate'' -e ''do…

JFD
- 21
- 1
2
votes
1 answer
How to define a persistent property in JXA
In AppleScript I would write
property foo: "value"
and the value would be saved between runs. How can I do this in Javascript for Automation?

Daniel Schlaug
- 1,504
- 1
- 13
- 17
2
votes
4 answers
How can one address two instances of the same application through osascript
Can anyone think of a workaround for the osascript index-by-name bottle-neck in its reference to multiple instances of the same application ?
If we obtain two process ids – one for each of two different instances of the same application, osascript…

houthakker
- 688
- 5
- 13
2
votes
1 answer
Osacript for Tmux sessions doesn't work after Brew Update
My spotify script does not execute since I ran brew update. Now my current Spotify or iTunes song doesn't render on my Tmux status bar.
I tried outputting a string and the script gives me text back so I do not think it's Osascript. I'm on Yosemite…

andy4thehuynh
- 2,042
- 3
- 27
- 37
2
votes
1 answer
Error when using Application.currentApplication() in JavaScript for Automation (OSA)
When using Application.currentApplication() in an OSA script, it issues the following warning when running it from the command line:
warning: failed to get scripting definition from /usr/bin/osascript; it may not be scriptable.
Why is this…

aaronk6
- 2,701
- 1
- 19
- 28
2
votes
2 answers
Bypass “Can't get window” error in AppleScript
I'm trying to make a bash script to close certain finder windows (I'm on MacOSX). Unfortunately, the script terminates as soon as the first window is found to not be open. (ex: No window titled "Communication" open, yet window "Editors" is open; No…

Miles Milosevich
- 23
- 6
2
votes
1 answer
NSTask completion
How do I provide a callback to know when a task has completed? Do I need to set up an NSRunLoop or something?
ObjC.import('Cocoa');
exec("/usr/bin/say",["hello"])
function done(notification) {
$.NSLog('Application done');
…

JakeCigar
- 603
- 6
- 12
2
votes
2 answers
Applescript: system-wide global variable accessible by all scripts
We have a PDF document processing system, implemented in AppleScript (where we call the scripts from the shell using osascript). In some of the scripts, we call Acrobat Preflight Droplets from the Applescript.
This does usually work without…

Max Wyss
- 3,549
- 2
- 20
- 26