MacOS command line tool which executes OSA scripts (AppleScript, JavaScript, etc.)
Questions tagged [osascript]
267 questions
0
votes
0 answers
MacOS - Add a Server to the saved servers list with command line
I'm trying to get a server into the "Favourite Servers" section.
Favourite Servers
The catch is: I want to do it with the terminal using "osascript" or "defaults write"
I searched for a bit and found this command:
osascript -e 'tell application…
0
votes
0 answers
MacOS - Automation setting gets unchecked on its own
System: macOS Monterey 12.0.1
I'm having an issue with my automation using osascript and I can't seem to find the way to solve it. I want to run a osascript code that will tell the System Events application to perform some actions.
Currently, when I…

Meru
- 77
- 13
0
votes
0 answers
Is there a way to get the list of applications in the Application Switcher in the same order using osascript?
I'm trying to use osascript to get the list of applications that appear in the application switcher (forgive me if that's not the correct name, but what appears when you run cmd + tab)
osascript -e 'tell application "System Events" to get the name…

ladder
- 189
- 2
- 9
0
votes
1 answer
Displaying an Xcode variable in a shell script in an alert fails to display the alert
I have a shell script that I run from Xcode to open the root folder in the Terminal. It works as expected when invoked by a function key in Xcode and opens a Terminal window pointing to the value of $SRCROOT as defined in Xcode and an alert with…

Alex Zavatone
- 4,106
- 36
- 54
0
votes
0 answers
How do I invert screen colors in Mac with a command line?
I would like to invert the screen colors with a script (osascript, bash, applescript or even with something in C code).
The closest thing I have found is toggle the dark theme.
> osascript -e 'tell app "System Events" to tell appearance preferences…

Pepe Segura
- 1
- 3
0
votes
2 answers
How to change volume on mac using osascript and OpenCV
I'm using a 14 inch M1 Pro Macbook Pro, running Mac OS Monterey 12.6.
I'm making an OpenCV and Mediapipe based Computer Vision Project that allows me to use hand detection to control my Mac's volume. The code detects the distance between the tips of…

MilkWithSalt
- 9
- 1
0
votes
0 answers
Allow AppleScript to run without asking for Permissions Monterey
I was wondering if there was a way to allow Applesript to run without asking for the initial pop-up permissions on Monterey?
Or is there a way to automate the acceptance of the pop-up permissions? Thank you in advance.
I have tried using SQLite3 to…

user43535
- 3
- 2
0
votes
0 answers
Run two processes in two different shell tabs automatically
I am making a shell script that starts the frontend and backend development servers for my node app. This means starting one server, opening a new tab, and starting the other.
The problem with my current script is that when it starts one server,…

Brian Barry
- 439
- 2
- 17
0
votes
0 answers
"osascript" with administrator privileges rejects any and all credentials
Something has broken in my macOS 12.x installation (currently 12.6) but I'm at a loss as to what it might be. A command such as this:
osascript -e 'do shell script "echo test" with administrator privileges'
...would previously pop up a prompt for a…

Andrew Hodgkinson
- 4,379
- 3
- 33
- 43
0
votes
2 answers
Run 2 commands in applescript/osascript with variable
I am trying to run 2 commands stored in a variable with osascript
This is my start.sh
currentDirectory="cd $(pwd) && npm run start"
echo $currentDirectory
osascript -e 'tell application "Terminal" to do script '"${currentDirectory}"''
I am…

LuisEnMarroquin
- 1,609
- 1
- 14
- 26
0
votes
2 answers
Defined bash commands not found when passed in "do shell script" in osascript
I am new to shell script and recently wrote a script to open a new terminal window and run defined functions via osascript with "do shell script", but the result showed the command not found. My script is as below:
#!/bin/bash
hello() {
echo…

Andy Lu
- 29
- 1
- 7
0
votes
1 answer
osascript: how to keep nested lists structure when output from command-line
I'm trying to code a script which can be able to extract the menu structure of a given app. This is a simplified working example:
tell application "System Events"
tell process "Terminal"
tell menu bar 1
set listA to name of…

Kalma
- 111
- 2
- 15
0
votes
0 answers
How to make a macOS app supports AppleScript ( Displaying Progress )?
I want my macOS app to display a modal progress bar like this:
and want to update the progress by AppleScript.
osascript -l JavaScript -e '
const app = Application("MyApp")
app.includeStandardAdditions = true
app.activate()
…

lonny
- 11
- 1
- 2
0
votes
1 answer
Spawn child process, then later send argument to that process
I want to spawn a child process, and then at a later time send an argument to it that will then execute. How can I do that? (NodeJS, on Mac)
For example, I have a command to execute a script file:
osascript script-test.scpt
This command works in…

SeanRtS
- 1,005
- 1
- 13
- 31
0
votes
0 answers
Execute multiple AppleScripts at once
Using macOS's Script Editor I made an application containing the following script. It accepts a plain text URL as an input. It works when I send it one input, let it finish executing the script, then send it a new input. If I send it a second input…

Dillon
- 119
- 1
- 3
- 13