Thursday, October 23, 2014

#1 2010-04-25 06:30:05 pm

lalcan
Member
Registered: 2010-04-02
Posts: 2

Proximity Scripts

So i've been playing with Proximity and some related scripts, i wrote them based on many other location aware scripts over the 'net, yet i think i've nailed some of the best ideas, i've been using them for some days now and i'm very happy with the way they behave.

They work like this:
When you walk away from your computer with your phone -even an iPhone, which i couldn't ever make work with Salling Clicker- it will ask if you're really away -a workaround to a weakness from Proximity program-, if you don't press a button, the script will activate the screen saver as well as the password protect, will save iTunes status and pause it gradually, then will save Skype and Adium status and set their status as away.

Once you come back, it will deactivate the password, quit the screen saver, restart iTunes and set Adium and Skype back to the status you had before leaving.

This couple of Applescripts avoid having to compile some stuff, or load any additional application, etc.

i think it might help someone else, and, as always, all your comments are welcome, with the community help i'm pretty sure we can make the best proximity scripts and provide a much needed central repository for all proximity related scripts.

Best regards

The "Going Away" script:

Applescript:


tell application "Finder"
   activate
   set results to display dialog " Lost contact with phone.
Screensaver will auto-activate"
buttons {"Ok", "Not"} default button "Not" with icon caution giving up after 5
   
   if (gave up of results is true) or (button returned of results is "Ok") then
       tell application "System Events"
           tell security preferences
               set require password to wake to true
           end tell
       end tell
       tell application "System Events"
           set listproc to name of every process
           if not (listproc contains "ScreenSaverEngine") then
               tell application "ScreenSaverEngine" to launch
           end if
           --ITUNES
           set musicbackg to listproc contains "iTunes"
           if musicbackg then
               tell application "iTunes"
                   if player state is playing then
                       set PlayState to player state
                       set old_volume to sound volume
                       repeat with i from old_volume to 0 by -1
                           set sound volume to i
                           delay 0.1
                       end repeat
                       pause
                       set comment of current track to "Proximity Paused"
                       set sound volume to old_volume
                   end if
               end tell
           end if
       end tell
       --ADIUM
       tell application "System Events"
           if ((get name of every process) contains "Adium") then
               tell application "Adium"
                   go away
                   set status message of every account to "I am away from my computer right now."
               end tell
           end if
       end tell
       --SKYPE
       tell application "System Events"
           if ((get name of every process) contains "Skype") then
               tell application "Skype"
                   set SkypeStatus to (send command "GET USERSTATUS" script name "StatusGetter")
                   if SkypeStatus = "USERSTATUS ONLINE" then
                       send command "SET USERSTATUS AWAY" script name "StatusSetter"
                   end if
               end tell
           end if
       end tell
   end if
end tell

The "Coming Back" script:

Applescript:


-- In this line, you have to change "YOUR PASSWORD" for your real password
set Pwd to "YOUR PASSWORD"
-- You don't need to modify anything below this line

tell application "System Events"
   --ScreenSaver
   if ((get name of every process) contains "ScreenSaverEngine") then
       tell application "ScreenSaverEngine" to quit
       delay 1
       tell application "System Events"
           keystroke Pwd
           tell application "System Events" to keystroke return
       end tell
   end if
   -- SKYPE
   tell application "System Events"
       if ((get name of the processes) contains "Skype") then
           tell application "Skype"
               set SkypeStatus to (send command "GET USERSTATUS" script name "StatusGetter")
               if SkypeStatus = "USERSTATUS AWAY" then
                   send command "SET USERSTATUS ONLINE" script name "StatusSetter"
               end if
           end tell
       end if
   end tell
   --ADIUM
   tell application "System Events"
       if ((get name of the processes) contains "Adium") then
           tell application "Adium"
               if status message of first account is "I am away from my computer right now." then
                   go available
               end if
           end tell
       end if
   end tell
   --iTunes
   if process "iTunes" exists then
       tell application "iTunes"
           if comment of current track is "Proximity Paused" then
               set comment of current track to ""
               set old_volume to sound volume
               set sound volume to 0
               play
               repeat with i from 0 to (old_volume) by 1
                   set sound volume to i
                   delay 0.1
               end repeat
           end if
       end tell
   end if
   tell application "System Events"
       tell security preferences
           set require password to wake to false
       end tell
   end tell
end tell


Filed under: back, location, Proximity, away

Offline

 

Board footer

Powered by FluxBB

[ Generated in 0.082 seconds, 8 queries executed ]

RSS (new topics) RSS (active topics)