Reputation: 81
there's some strange behavior in Applescript. I got this script
property tmpUrl:"http://www.example.com"
on run argv
if(count argv) > 0 then
set tmpUrl to item 1 of argv
end if
if running of application "Safari" then
tell application "Safari"
activate
make new document with properties{URL:tmpUrl}
end tell
else
tell application "Safari"
activate
set URL of document 1 to tmpUrl
end tell
end if
end run
As you can see from the code, it should always open a new window. If Safari is already running it does not need to make a new window. It'll use the automatically opened window and just change the location.
When I run this with scripteditor everything works as expected. But when i call it from bash with:
osascript web_win_open.applescript "http://www.stackoverflow.com"
it always acts like Safari was running. So if Safari isn't running it pops up two windows. One with the homepage and one with the location from cli.
What's different and how do you fix this?
Upvotes: 0
Views: 387
Reputation: 19032
If Safari is already running it does not need to make a new window.
Your code seems to be backwards. Under "if running of application "Safari" then you are telling it to make a new document when that's the case for using document 1. Just rearrange your code, it's backwards.
Upvotes: 1