MacOS command line tool which executes OSA scripts (AppleScript, JavaScript, etc.)
Questions tagged [osascript]
267 questions
3
votes
1 answer
How to preview file contents from command line, instead of Finder.app
From a command-line in a terminal, is there any way to bring up the preview file contents screen that can be seen in Finder.app when pressing the spacebar -- without bringing Finder.app to the foreground with focus (i.e., keep Finder.app…

lawlist
- 13,099
- 3
- 49
- 158
3
votes
2 answers
How do you get the playtime of an iTunes track with applescript?
I'm just starting to play around with Geektool and applescripting to make my mac desktop fun and I've run into a question I can't seem to find an answer to. How do you get the current song playtime from an osascript command? I've found great…

sanpaco
- 785
- 1
- 14
- 32
3
votes
3 answers
Trouble escaping quotes in a shell script
I have a bash script I am making that generates some numbers assignes them to variables then uses osascript to write them out in any application of choice.
Here is a simplified version of what I want to do.
monday1=5
osascript -e 'tell application…
user2433573
3
votes
2 answers
Why doesn't this simple AppleScript work?
I have a Shell Script where I need to create aliases folders on a MacOSX 10.6.X so I call osascript to do it with the code below:
Source="/Volumes/Test Project/Folder/SubFolder"
Destination="/Volumes/Test Project/Dest/"
/usr/bin/osascript -e 'tell…

Arthur Alves
- 458
- 1
- 5
- 13
2
votes
1 answer
Getting iTunes lyrics usings osascript
I'm trying to get the lyrics to the current playing song in iTunes using osascript. The command I'm using is:
osascript -e '''tell application "iTunes" to lyrics of the current track'''
The problem with this is that I'm only getting the last line…

Federico Builes
- 4,939
- 4
- 34
- 48
2
votes
1 answer
osascript 'do shell script' line endings
I'm trying to debug an larger osascript 'do shell script' program and have narrowed the problem down to a much shorter repro case that I don't understand at all. Here's the repro case:
osascript -e 'do shell script "echo 123; echo 45; echo…

Nick Santos
- 45
- 3
2
votes
2 answers
Multiple Applescript lines from terminal osascript call
So I'm trying to run multiple Applescript commands from the command line in one go. However, no matter how I try it, it won't work:
$ osascript -e "set x to 0; display dialog x"
$ osascript -e "set x to 0 \n display dialog x"
$ osascript -e "set x…

gurkensaas
- 793
- 1
- 5
- 29
2
votes
1 answer
Copy multiple POSIX files to clipboard with applescript
I'm trying to copy multiple files to the clipboard in macos like this:
./file2clip.applescript /User/Cool/Dekstop/test.txt /User/Cool/Dekstop/myfolder
I already can do this with only one file:
#!/usr/bin/osascript
on run args
set the clipboard…

lordcommander
- 320
- 3
- 7
2
votes
2 answers
exec osascript(AppleScript) from within NodeJS
I know I am probably missing this hugely,
but anyone knows why this keeps returning an error?
$ node -v && node
v0.4.6
> var cmd = 'osascript -e "open location \"http://google.com\""';
> require('child_process').exec(cmd, function (error, stdout,…

zanona
- 12,345
- 25
- 86
- 141
2
votes
0 answers
Run CGSession -switchToUserID on remote Mac
I have next script on my remote Mac:
on run
do shell script "/System/Library/CoreServices/Menu\\ Extras/User.menu/Contents/Resources/CGSession -switchToUserID 502"
delay 5
tell application "System Events"
keystroke "mypassword" &…

Rougher
- 834
- 5
- 19
- 46
2
votes
2 answers
macOS send keystroke to the active app periodically
I am trying to send a keystroke (command+ shift+ r) to a macOS (Mojave) app called "Dbeaver" every minute as long as DBeaver is the active app. I have tried the following with no effect.
tell application "System Events"
set activeApp to name of…

gibbz00
- 1,947
- 1
- 19
- 31
2
votes
2 answers
cmd.Run() hangs forever in golang on Macos when the screen is locked/off
I am running a golang app on Macos. It has some codes like the following:
for {
time.Sleep(time.Second * 5)
cmd := exec.Command("/usr/bin/osascript", "-e", `display dialog "hello" with title "hello"`)
err := cmd.Run()
}
It works fine if…

sgon00
- 4,879
- 1
- 43
- 59
2
votes
0 answers
Terminal: Add items to Accessibility Access in MacOS Mojave 10.14?
Is there a way to programmatically add items (Osascript) to Accessibility Access?
I read its possible via tccutil, for example:
sudo tccutil.py --insert /usr/bin/osascript
Mojave is not letting me do this: "Error opening Database", seems like TCC…

samecat
- 335
- 1
- 11
2
votes
1 answer
Bash osascript(AppleScript) in mac terminal, run multiple commands sequentially
I am trying to create a bash .sh script file that uses osascript to open 1 new terminal window/tab and then runs 2 commands "cd fs" and than "gulp" (both in the same window/tab)
This is what I am trying and it runs the second command (do script…

gotime4
- 309
- 1
- 13
2
votes
1 answer
Identifying Terminal window in AppleScript
I'm trying to make my Terminal change profiles when I run ssh. To this end, I wrote this script (and defined an alias so ssh would run it):
#!/bin/bash
osascript -e "tell application \"Terminal\" to set current settings \
of front window to first…

Amadan
- 191,408
- 23
- 240
- 301