Question

I have an applescript. The script goes like this..

tell application "Safari"
  open location "http://www.google.com" -- mentions the perticular webpage to be loaded
  activate --makes the Safari application the front most application
end tell

Whenever I open this script, the Safari application gets launched. To be very clear, I'm not running this application instead I am just opening this script in applescript editor.

Can anyone please explain me why the Safari is getting launched. The Safari gets launched but it will be hidden or say it does not put up any window. [Neither it does load any pages in the background, it just gets launched in the dock and a dot saying that the app is launched will be present].

Once I run the script then the safari puts up the window and loads the desired web-page.

Please Help.

Was it helpful?

Solution

In general, applescript must launch an application to learn what commands it understands. Over time applescript has gotten better at not launching applications for this task, but some apps still get launched. iPhoto is one I notice gets launched when I open applescripts that use it. As such it's not something you can avoid.

However, in your case there may be a fix. The "open location" command is a generic applescript command. You do not need to tell Safari to execute that command. Therefore you can probably change your script to this and avoid the launching issue. The open location command should just open the link in your default browser which I assume in your case is Safari. It should also automatically activate it for you.

Good luck.

open location "http://www.google.com"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top