MacOS command line tool which executes OSA scripts (AppleScript, JavaScript, etc.)
Questions tagged [osascript]
267 questions
6
votes
1 answer
What does ${1-1} in bash mean?
I'm reading the scripts from here and trying to understand what's going on. This function performs changing the directory of a Finder window:
function ee {
osascript -e 'set cwd to do shell script "pwd"'\
-e 'tell application "Finder"'\
-e "if…

myxal
- 87
- 1
- 7
5
votes
1 answer
AppleScript Runner exit status passed back to shell script
I need to be able to run AppleScript in a shell script. I am using "AppleScript Runner" in order to be in interactive mode, so that dialogs etc. are supported. I've got it working, but I need to get the exit status of the AppleScript Runner app back…

krill
- 199
- 5
5
votes
1 answer
AppleScript that reads active application name, title and URL
I need AppleScript that, when lunched from command line, will return three things:
current active application name; ex. "Google Chrome", "Safari",
"Steam", "iTunes", "Atom" ect.
current active application title, if there is one
if current active…

Tomasz Giba
- 507
- 1
- 8
- 22
5
votes
2 answers
How to display modal window using osascript or AppleScript in OS X
How to display modal(over all apps, windows) window using osascript or AppleScript in OS X 10.6.8 and later.
Here a script I do:
#!/bin/bash
osascript -e 'tell app "System Events" to display dialog "My Dialog" buttons {"OK"} default button 1 with…

Serge
- 2,031
- 3
- 33
- 56
4
votes
1 answer
How can I get rid of this osascript output?
The following question relates to an answer that was posted on this question:
I like the notion of creating my own function that opens a new terminal, so the script that Craig Walker linked to in that above-referenced question suited my needs. The…

barclay
- 4,362
- 9
- 48
- 68
4
votes
2 answers
How can I as generically as possible grab all text from the frontmost window/document on OSX?
I want to be able to grab all the text from the frontmost window on my screen, pipe it to a url parser and choose which url to open from the parsed text.
To do this I would need a way to access all textual contents of the frontmost window. I've come…

brujoand
- 815
- 8
- 15
4
votes
5 answers
How to close a Terminal tab using AppleScript?
I'm using AppleScript to open PostgreSQL in a Terminal tab like this:
#!/bin/bash
function new_tab() {
TAB_NAME=$1
COMMAND=$2
osascript \
-e "tell application \"Terminal\"" \
-e "tell application \"System Events\" to keystroke \"t\"…

David Morales
- 17,816
- 12
- 77
- 105
4
votes
1 answer
Wait until a certain application has exited, then launch another one
On OS X I want to execute an osascript command that waits until a certain application specified by its full .app path has exited, then start another application, e.g. using /usr/bin/open -n /Applications/MyApp.app.
How to achieve the waiting until…

Thomas S.
- 5,804
- 5
- 37
- 72
4
votes
2 answers
Terminal Applescript unable to escape quote
I've run into a strange problem when trying to include quote marks ' ' in my osascript command.
If I try and escape a normal escapable character, it works fine. Example: osascript -e 'tell app "Finder" to display dialog "Te\\st"' A dialog box from…

JamEngulfer
- 747
- 4
- 11
- 33
4
votes
1 answer
call mac multimedia keys (playpause / prev / forward) by osascript
I am creating android remote controller for mac and for simplicity I want the same behavior in my app like behave standard multimedia keys on mac (F7, F8, F9).
I have installed "Key Codes" app on my mac but it doesn't recognized multimedia keys.
I…

jakub
- 3,576
- 3
- 29
- 55
4
votes
2 answers
App giving "cant open .app because classic environment is not supported" on other macs but works fine on my own
I have written an app that is a bash script, the whole thing is a bash script, and it calls a few osascripts, also for user input mostly, it works awesome on my computer, and so I used platypus to turn the script into an app so that I could send it…

Durpdurpdurp
- 139
- 1
- 6
4
votes
2 answers
Osascript - syntax error when run from daemon (LiveCode app)
I have a LiveCode app that, as part of a larger purpose, checks to see what the name of the "frontmost" application (i.e. the name in the menu bar). I am having LiveCode run this through the shell:
osascript -e 'tell application "System Events" to…

Nextyoyoma
- 41
- 1
3
votes
2 answers
What are error -10004 and error -10000 in Applescript
I have an Applescript that is working on my computer, but not on my colleague's. I get two errors when manipulating paths: -10004 and -10000. I have an idea on how to solve this, but first I'd like to understand those error codes.
Here is the script…

charlax
- 25,125
- 19
- 60
- 71
3
votes
0 answers
Passing an NSArray populated with NSDictionaries to a NSAppleScript
So I have an Apple Script that is running one of the functions of my program like so:
[ NSThread detachNewThreadSelector:@selector(runAppleScriptTask)
toTarget:self
withObject:nil];
Using this…

acidprime
- 279
- 3
- 18
3
votes
2 answers
macOS: How to access the Live Text OCR functionality from AppleScript/JXA?
As of macOS Monterey it is possible to select text in images in Preview.
Is this OCR functionality available from AppleScript and/or JXA (JavaScript for Automation)?
In Script Editor.app File > Open dictionary... I selected the Preview.app and…

ccpizza
- 28,968
- 18
- 162
- 169