AppleScript: Location Manager 2.0 Scripting

How can I script Location Manager version 2.0?
The Location Manager 2.0 has some limited scripting capability.

The ability to use the AppleScript "every" phrase is not yet implemented, however this facility can be worked around by doing a little more scripting.

Example 1

tell application "Location Manager" to get the name of every location -- doesn't work in version 2.0

An example solution to the above limitation is:

set LocationNames to {} -- start with a null list
tell application "Location Manager"
repeat with i from 1 to count of locations
copy name of location i to LocationNames
end
end

At the end of this script's execution, the variable LocationNames will be a list of every location name.


Example 2

tell application "Location Manager" to get the name of the current location -- doesn't work in version 2.0

An example solution to the above limitation is:

set CurrentLocName to "" -- start with a null string
tell application "Location Manager"
repeat with i from 1 to count of locations
if location i is the current location then
copy name of location i to CurrentLocName
end
end
end

At the end of this script's execution, the variable CurrentLocName will be the name of the current location.
Published Date: Feb 18, 2012