0

I'm trying to open a URL in Safari. It works fine for websites without Flash embedded, but crashes Safari for Flash sites.

Example (this WORKS):

tell application "Safari" to open location "http://google.com"

This CRASHES when Safari is not already running:

tell application "Safari" to open location "http://grooveshark.com"

Two things I noticed:

  • Safari only crashes for websites with embedded Flash
  • The script above only crashes if a new instance of Safari is created (i.e. Safari was not running before)

From the second observation I assume that it could be a permission issue of some sort. Maybe the Safari instance launched from the AppleScript has a problem loading plugins?

Mark
  • 343
  • 1
  • 4
  • 13
  • Not an applescript issue. Also happens for [NSWorkspace openURL:] See here: http://www.idevgames.com/mybb/showthread.php?tid=1886 – Mark Jun 04 '10 at 06:47
  • Actually, maybe it is an Applescript problem as well. I noticed that the NSWorkspace crash only occurs when the test program is started from XCode. Launched from Finder it works fine. However, the Applescript above fails when run in the Script Editor. – Mark Jun 04 '10 at 07:00

2 Answers2

1

Did you know "open location" is not a Safari applescript command? As such you shouldn't tell safari to run that command. "Open location" is in the standard additions to applescript and it's used to open a url in the default application that handles the url. Plus, if Safari is the default application for a user, and if it crashes if safari isn't already running, then why not launch safari first, then call your command... I haven't tried this... it's just a suggestion...

tell application "Safari" to launch
open location "http://grooveshark.com"

By the way, if you want to make sure safari is used, then you open the url like this...

tell application "Safari"
    launch
    make new document
    tell document 1 to set URL to "http://grooveshark.com"
end tell
regulus6633
  • 18,848
  • 5
  • 41
  • 49
  • Thanks for your answer. For some reason the even the first applescript now works. Maybe XCode somehow broke things. In other forums where this problem is mentioned, people also ran XCode before that error occurred. – Mark Jun 05 '10 at 10:13
0

I had come across a similar issue some time back while working on Xcode. I realized later that it was caused by an asset in Flash. If you turn your applescript into an application, the problem should be solved.

On Xcode, go to Run -> Stop on Debugger()/DebugStr() and uncheck the option if it is on and build your application again.

Vishvesh
  • 512
  • 8
  • 21