If exists of application process "Safari" is true then On older systems, the syntax used to be: tell application "System Events" do stuff you want to do only if Safari exists If application process "Safari" exists then The simple code to achieve what you want(ed) is: tell application "System Events" OK, I know this question is really old, but I stumbled on it looking for a different issue and had to pipe in considering how complicated some of these responses are. Osascript /Users/USERNAME/Desktop/foo.applescript This will work ok and you can also save and use it as a plain text script. Notice that the script is saved as a compiled script. Osascript /Users/USERNAME/Desktop/foo.scpt This script can be run from the command line with osascript Tell application id (id of application appName) As it does work but feel the Answer is not clear enough so I will give an example on using it. I actually like user1804762 method below. The answer works and is not trying to be elegant. The method I used above was from a old script I had used to solved this issue a while before I answered here. It will be easier if you write the script in a normal applescript document first and compiled it to check for errors. You will need to escape any characters like quotes as in my example. The script in the run script is only compiled when needed. scpt file and want to use a plain text file then you could try the trick of putting a run script command in the applescript. scpt does not cause this behaviour because the is no compiling to be done.īut calling it from a plain text (.txt.sh ) file will so the app will launch. The act of compiling on a tell application will afaik make the app launch.Ĭalling the script from the command line with osascript from a pre-compiled file i.e. I suspect the reason you are getting this is because each time you call the script from the command line with osascript the script is being compiled. I'm not aware of any way to run this script from python without using osascript, other than appscript, which I don't want to use because it's no longer developed/supported/recommended. I've boiled down that undesirable behaviour to the simple test case shown above. So, does anyone have any ideas about how I might fix or route around this? Is it an osascript bug? Or am I missing something about AppleScript's semantics?įor context: I'm trying to write a script (to be embedded/called from some python) which queries open browsers for the URLs of any tabs they have open I've got it all working fine except that it always launches Safari, whether it's open or not.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |