Applescript / Growl SSID notification how to?

Discussion in 'Mac Programming' started by Polansky, Oct 13, 2012.

  1. Polansky macrumors newbie

    Nov 2, 2010
    I would like to retrieve the SSID within Applescript from the current WiFi connection and then make a notification of the SSID address via Growl (not hardwaregrowler).

    How do I do this?

    Within Applescript I know you can read out the SSID via:

    set SSID to do shell script "/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I | awk -F':' '/ SSID/ {print $2}'"

    The result is then the name of the WiFi network to which my computer is connected. However I do not know how to make a hook that would show the result as a Growl message.

    Via the following shell script I can make the SSID and BSSID visible :
    /System/Library/PrivateFrameworks/Apple80211.\framework/Versions/A/Resources/airport --getinfo | grep SSID

    This gives me an even better result, but how do I parse the output to Growl as a notification that I am connected to that specific network?
  2. chown33 macrumors 604

    Aug 9, 2009
    on the Western Slopes, with E. A. Poe
  3. Polansky thread starter macrumors newbie

    Nov 2, 2010
    Thanks, I've seen that too already.

    But I can not find any information about showing any dynamic content within Growl. Next to that I am fairly new to programming and some of the information is just too difficult to understand for me.

    It would be great if somebody would be willing to write this little script so I would be able to use it right away.
  4. kryten2, Oct 13, 2012
    Last edited: Oct 14, 2012

    kryten2 macrumors 6502a

    Mar 17, 2012
    Try this :

    tell application "System Events"
    	set isRunning to (count of (every process whose bundle identifier is "com.Growl.GrowlHelperApp")) > 0
    end tell
    --make the SSID and BSSID visible :
    set the_message to do shell script "/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport --getinfo | grep SSID"
    if isRunning then
    	sendGrowl("SSID and BSSID", "WiFi network", the_message)
    end if
    on sendGrowl(growlName, growlTitle, growlDescription)
    		tell application "GrowlHelperApp"
    			-- Make a list of all the notification types 
    			-- that this script will ever send:
    			set the allNotificationsList to {"SSID and BSSID"}
    			-- Make a list of the notifications 
    			-- that will be enabled by default.      
    			-- Those not enabled by default can be enabled later 
    			-- in the 'Applications' tab of the growl prefpane.
    			set the enabledNotificationsList to {"SSID and BSSID"}
    			-- Register our script with growl.
    			-- You can optionally (as here) set a default icon 
    			-- for this script's notifications.
    			register as application ¬
    				"Show SSID and BSSID" all notifications allNotificationsList ¬
    				default notifications enabledNotificationsList ¬
    				icon of application "Terminal"
    			-- Send a Notification...
    			notify with name growlName ¬
    				title growlTitle ¬
    				description growlDescription ¬
    				application name "Show SSID and BSSID"
    		end tell
    	on error growlError
    		display dialog "Growl Error:" & return & growlError
    	end try
    end sendGrowl
    Note : not tested because I made it quickly and I'm not connected through WiFi.
  5. Polansky thread starter macrumors newbie

    Nov 2, 2010
    You can do Magic - Works like a charm!
    Tried all evening (live in europe) to get it to work and you do it instantly.
  6. kryten2 macrumors 6502a

    Mar 17, 2012
    Glad it worked. It should give you something to work with if you decide to include your first do shell script or if you want to change the icon of the notification.
  7. Polansky thread starter macrumors newbie

    Nov 2, 2010
    Changing the notification icon is the easy part :)
    Also a big thank you for adding the comments as this helps me understanding how the script works.

Share This Page