Sunday, September 6, 2009

My First Apple Script SpySafari.

Since the day I bought my mac I am in love with Safari (yeah I am a mac buff :) ) The best browser around. Any ways coming to the point of this post. Last night I was searching for an option to enable the "Private browsing" option automatically and stay selected always but there is no way to do that in safari. Though we can manually select this option from the menu Safari -> "Private Browsing". We have to do this every time we open safari and have to click "OK" on the confirmation box . So I started to look for ways to automate this action thus Applescript was the answer So I started to fool around with applescript this is my first script hence had to do some learning from the apple script manual 10 minutes later I was all set to experiment and 2 hours later I had this final version running perfectly.Yeah it was that simple , I found many similar scripts already available on the internet but 99.9 % of these scripts were incomplete. what I mean is :


1. Many of the scripts never check if UI element was enable in system preferences -> universal access before running the script , this check is essential because if UI element is not enabled then this GUI based script will fail to execute and throws annoying errors.


2. Secondly, Most of the scripts just did a toggling function. i.e; if the script was run with "private Browsing" already enabled in safari then the script actually disabled it ( haha.. this was funny). almost all scripts had this issue.


3. There is only one perfectly working script by Tomx called SafariPB , but the source code is not provided along with it though the app is free.


hence for the above mentioned reasons I though of writing my own script and sharing it :)


here is how this scripts works :


1. Checks if UI element is enabled

2. If UI element is not enabled , then enable it with user's permission

3. Check if "Private browsing" is enabled in Safari

4. If not already enabled then enable it, If already enabled then do nothing or open a new Safari window if no Safari windows are open.


I am pleased to say that the prestigious www.macupdate.com has accepted SpySafari to be hosted on their site

download from macupdate Spy Safari



Download from my site( converted as a mac app and zipped) - use this to launch Safari instead of the usual Safari icon - Works on any version of mac OS (universal).


To edit the script go tot the main.scpt inside package content and edit wit script editor.


Once you save SpySafari app on your mac just open it as any other application. SpySafari opens Safari with "private Browsing" enabled and automatically quits.


P.S. I named it spy safari just for the kicks :) and can anyone tell me the best way to share it with the world ??


2 comments:

  1. Hi macc Buff,

    Great to hear about MACC Intro, that to from a TECHIE like you. Oh!!! It's a wonderful bloging Experiance.

    Write About your MAC using your mother tongue("WRITE SHORT NOTE"). Let us see how good it sounds.

    Keep Rocking....your MACC

    Thanks
    Kiran

    ReplyDelete
  2. Hi Rajiv! Write from Italy. I am a recent switcher! Tried to launch SpySafari but I got an Error message warning me "impossible to obtain". Do not know whether the problem is the same but prior I was unable to launch Safari PB as well. In that case Error message said that the script would not run on my Mac because it appears I am using a non English keyboard. Mine is a QWERTY keyboards with 79 (ISO) keys. Any idea? Is there any log file for System or Events Errors in Mac OS X Snow Leopard 10.6.1? Thanx.
    M.A.U.

    ReplyDelete