AppleScript - Force Open Safari

Discussion in 'Mac Basics and Help' started by John Doe 57, May 26, 2008.

  1. John Doe 57 macrumors 65816

    John Doe 57

    Joined:
    Jan 26, 2008
    Location:
    Los Angeles, CA
    #1
    Can i use AppleScript to Force open Safari. My Safari is broken and only responds to this:
    sudo -k; sudo -b '/Applications/Safari.app/Contents/MacOS/Safari'

    This is the command I use to open Safari with the help of Terminal.

    Is there some way that I can get a script that runs off Terminal commands? And can I save that as an application that would load up Safari?
     
  2. chas0001 macrumors 6502a

    chas0001

    Joined:
    Sep 18, 2006
    Location:
    Alicante, SPAIN
    #2
    You can issue terminal commands in AppleScript using the command

    do shell script " ** put your code here ** " e.g.

    do shell script "ls -l"

    You can then save the AppleScript as an Application using Script Editor.

    Is that what you meant?
     
  3. John Doe 57 thread starter macrumors 65816

    John Doe 57

    Joined:
    Jan 26, 2008
    Location:
    Los Angeles, CA
    #3
    Oops! That command requires my password! Forgot to tell you.
     
  4. chas0001 macrumors 6502a

    chas0001

    Joined:
    Sep 18, 2006
    Location:
    Alicante, SPAIN
    #4
    You can do this but its not very secure :

    Example code :

    do shell script "sudo shutdown -h now" password " ** your password here ** " with administrator privileges
     
  5. John Doe 57 thread starter macrumors 65816

    John Doe 57

    Joined:
    Jan 26, 2008
    Location:
    Los Angeles, CA
    #5
    Its not working. Here is what I have:

    do shell script "sudo -k; sudo -b '/Applications/Safari.app/Contents/MacOS/Safari'"

    do shell script "ls -l"

    do shell script "sudo shutdown -h now"gmbmatrix" with administrator privileges

    Picture 1.png
     
  6. chas0001 macrumors 6502a

    chas0001

    Joined:
    Sep 18, 2006
    Location:
    Alicante, SPAIN
    #6
    Thats because you have typos. All you need to open safari is

    do shell script "sudo -k; sudo -b '/Applications/Safari.app/Contents/MacOS/Safari'" password "gmbmatrix" with administrator privileges

    You dont need the last 2 'do shell scripts' because they were purely examples. Just for future reference the typo was due to double quotes in the wrong place and the missing word Password i.e. do shell script "sudo shutdown -h now" password "gmbmatrix" with administrator privileges

    I am sure that you have tried to resolve the problem with safari by removing it and its preference files then downloading the latest version of Safari from the Apple Website.
     
  7. John Doe 57 thread starter macrumors 65816

    John Doe 57

    Joined:
    Jan 26, 2008
    Location:
    Los Angeles, CA
    #7
    Thanks a million! It worked. Although this happens every time I open the Safari script application:
    Picture 1.png
     
  8. merl1n macrumors 65816

    merl1n

    Joined:
    Mar 30, 2008
    Location:
    New Jersey, USA
    #8
    Excuse me for asking, but what do you mean when you say Safari is broken? What are your symptoms? If you can open it in Terminal, then I don't think it's broken.

    It could be a binding issue or your "locate db" is bad or something else like a bad cache file. Please explain.
     
  9. John Doe 57 thread starter macrumors 65816

    John Doe 57

    Joined:
    Jan 26, 2008
    Location:
    Los Angeles, CA
    #9
    Yeah what I mean is that Safari does not open anymore. On May 20th it just stopped working. I couldn't get it to open. It would just load and load. Firefox works perfectly. I've deleted files in the preferences and it seems to do nothing. Terminal is the only way that I can open Safari. But I can't download anything using Safari anymore, I have to use Firefox. So I created a new username and tried to see if Safari would work - It did. But that is just plain annoying! Logging into another account just to use Safari, its stupid really. And as for this new issue regarding keychains, I don't know. That box appears during startup and anytime I click on a bookmark in Safari.

    If you know how to fix it - please help me.
     
  10. merl1n macrumors 65816

    merl1n

    Joined:
    Mar 30, 2008
    Location:
    New Jersey, USA
    #10
    You just proved my point. If it works with another user account then it's not broken. Most likely your Safari plist file is corrupted or you have some bad user cache file.

    This is what you should do:

    1. Download OnyX (a free maintenance utility).
    2. Go into your homedirectory/Library/Internet Plug-Ins and remove (you can move it all to your desktop or another folder) everything.
    3. Delete the "com.apple.Safari.plist" and "com.apple.Safari.RSS.plist" files in your homedirectory/Library/Preferences folder.
    4. Run OnyX and clear ALL caches (System, Fonts, User, etc.). Note, in each tab, execute the command. When it finished in that tab, it will ask you to reboot. Say NO. Go on to the next tab and repeat until all tabs are done. THEN REBOOT.

    Now see if you have any problems launching Safari.
     
  11. merl1n macrumors 65816

    merl1n

    Joined:
    Mar 30, 2008
    Location:
    New Jersey, USA
    #11
    Sorry I forgot about your keychain problem.

    In /Applications/Utilities, there is an application called Keychain Access. Launch it. Under the "Keychain Access" menu, select "Keychain First Aid". Run that.
     
  12. John Doe 57 thread starter macrumors 65816

    John Doe 57

    Joined:
    Jan 26, 2008
    Location:
    Los Angeles, CA
    #12
    YES!!!!!!!!!!

    It works!!!! Thank you so much!!!!


    Everything is back to normal!
     

Share This Page