open programs with applescript

Go To StackoverFlow.com

15

2 part question:

I'm simply trying to run programs using applescript from the terminal, so I tried:

$ osascript tell application "iTunes" to activate

and get the error:

osascript: tell: No such file or directory

Giving the full path to the program did not work either. What am I missing? The second part of the question is what I eventually want to use applescript for. I would like to use it to open an application I built using py2app. Can applescript open any mac app or just certain ones that are already compatible.

Thanks

2012-04-05 03:08
by sabajt


20

Try this. Notice you use "-e" when you are writing the command. Without "-e" you would give a path to an applescript to run. Also notice the string command must be in quotes.

osascript -e "tell application \"iTunes\" to activate"

And if you have a multi-line applescript you use "-e" before each line like this...

osascript -e "tell application \"iTunes\"" -e "activate" -e "end tell"

If you want to open an application just use the unix "open" command...

open "/path/to/application"

If you wanted to open an application using applescript and the "activate" command doesn't work (it should work for almost everything though) then tell the Finder to open it. Remember that applescript uses colon delimited paths...

osascript -e "tell application \"Finder\" to open file \"path:to:application\""
2012-04-05 07:02
by regulus6633
Is it possible to tell which workspace to be opened on - Someth Victory 2015-06-10 09:35
The big lesson I learned here is that single quotes won't work. You gotta use double quotes for the -e arguments - kakyo 2018-05-24 14:03


8

In a bash shell (like in Terminal), you can send multiple lines to osascript by using a "here document".

osascript -e "tell application \"iTunes\"" -e "activate" -e "end tell"

becomes

osascript <<EOF
tell application "iTunes"
   activate
end tell
EOF

As an old-skool Unix hacker, I save these little snippets in my $HOME/bin directory and call them from the command line. Still learning the particulars, though.

Alan

2013-01-12 14:42
by Alan Porter


5

Try:

do shell script "open /Applications/iTunes.app"
2012-04-05 19:44
by adayzdone


5

you need to put single quotes around the tell:

osascript -e 'tell app "iTunes" to activate'

otherwise you're defining a variable when you run -e

2012-12-31 17:53
by adus caeim
Can you point to some documentation where this is explained? Looking through the man page for osascript I do not see this mentioned - regulus6633 2015-06-28 08:00


4

an alternative to osascript:

open -a Calendar

close by:

pkill Calendar
2016-06-15 22:31
by Darth Coder


1

I'am new to script too.

I am confused to so I scan an essay named AppleScript Language Guide and when I go through script commands items, I learn that if you want to activate an application in mac os with applescript editor you should type beneath code in your editor and then compile and run them! may this answer will help you, here's code:

// applescript editor code    

----------    

activate application "iTunes" line 1    

----------    

tell application "iTunes" to activate line 2
2013-01-30 12:47
by Vincent Hsu
Ads