Playing with Proximity

Posted on 2007-11-14 21:00:31 EET.

I finally took the time to polish a bit more a few Proximity scripts that I have used. Inspiration and code to get started from this post.

Since in my experience the proximity detection can be bit flaky if you put it to scan very often (for the screensaver use as outlined in the post) and there is battery to be considered and also I have had some issues with Bluetooth mouse those times, I now only use the in-range script (polling at 10mins) and even that to only do backup of my address book and calendar and then run iSync.

While Proximity does not have the handy "open at login" right at preferences/settings, you can easily enough add it via "System Preferences" -> "Accounts" -> "Login items".

Here are the scripts

in-range.scpt (btw requiring .scpt in stead of `.applescript or allowing any extension is one of my pet peeves with Proximity):

-- Backup data and sync phone
tell application "iSync"
    -- if it's been >15 min since last sync
    if last sync is less than ((current date) - 900) then
        -- Dump backups files with the refactored scripts
        do shell script "/usr/bin/osascript /opt/local/bin/ical2vcal.applescript"
        do shell script "/usr/bin/osascript /opt/local/bin/address_book2vcards.applescript"
        -- backup the documents folder
        do shell script "/sw/bin/rdiff-backup ~/Documents/ ~/rdiff/Documents/"
        -- Launch sync (this will be done on background so the call returns immediately)
        synchronize
    end if
end tell
-- hide the isync window from cluttering our view
tell application "System Events" to set visible of process "iSync" to false

The /opt/local/bin/ical2vcal.applescript referred above:

-- Backup ical as vcals
tell application "iCal" to activate
delay 2
tell application "System Events"
    tell process "iCal"
        select row 1 of outline 1 of scroll area 2 of window "iCal"
        select text field 1 of row 1 of outline 1 of scroll area 2 of window "iCal"
        try
            tell text field 1 of row 1 of outline 1 of scroll area 2 of window "iCal"
                set {xPosition, yPosition} to position
                set {xSize, ySize} to size
            end tell
            -- modify offsets if hot spot is not centered:
            click at {xPosition + (xSize div 2), yPosition + (ySize div 2)}
        end try
        try
            click menu item "Export…" of menu 1 of menu bar item "File" of menu bar 1
            set value of text field 1 of sheet 1 of window "iCal" to "calendar_home"
            (* crashes 
            click pop up button 1 of sheet 1 of window "iCal"
            sleep 2
            click menu item "Documents" of menu 1 of pop up button 1 of sheet 1 of window "iCal"
            sleep 2
            *)
            click button "Export" of sheet 1 of window "iCal"
            try
                click button "Replace" of window 1
            end try
        end try
    end tell
end tell
tell application "System Events" to set visible of process "iCal" to false

The /opt/local/bin/address_book2vcards.applescript referred above:

-- Backup ical as vcals
tell application "iCal" to activate
delay 2
tell application "System Events"
    tell process "iCal"
        select row 1 of outline 1 of scroll area 2 of window "iCal"
        select text field 1 of row 1 of outline 1 of scroll area 2 of window "iCal"
        try
            tell text field 1 of row 1 of outline 1 of scroll area 2 of window "iCal"
                set {xPosition, yPosition} to position
                set {xSize, ySize} to size
            end tell
            -- modify offsets if hot spot is not centered:
            click at {xPosition + (xSize div 2), yPosition + (ySize div 2)}
        end try
        try
            click menu item "Export…" of menu 1 of menu bar item "File" of menu bar 1
            set value of text field 1 of sheet 1 of window "iCal" to "calendar_home"
            (* crashes 
            click pop up button 1 of sheet 1 of window "iCal"
            sleep 2
            click menu item "Documents" of menu 1 of pop up button 1 of sheet 1 of window "iCal"
            sleep 2
            *)
            click button "Export" of sheet 1 of window "iCal"
            try
                click button "Replace" of window 1
            end try
        end try
    end tell
end tell
tell application "System Events" to set visible of process "iCal" to false

I haven't tried Salling clicker (my N93 wasn't supported at the time) but do know it exists.

Update

Home Zone Looks very promising for this and many other uses (much, much more flexible), I'll have to play around with it sometime in the near(ish) future.

Back

Layout Copyright © 2006 Finnish Teleservice Center Ltd Oy - Site Powered by Midgard CMS