Hi there. I’m failing horribly at this. All I want is to grab the current location from within Google Earth and dump it into the clipboard. Here’s my code…
tell application "Google Earth"
set loc to ({latitude, longitude}) of (GetViewInfo)
set the clipboard to loc
end tell
The script runs with no errors, but nothing makes it into the clipboard. If I remove the "the from the 3rd line, I get an error that displays my current location from Google Earth, so I know that portion of it is working. Any help would be appreciated. Thanks.
Hi,
The only way I was able to get coordinates from Google Earth was to use the GUI to enter the location into the “Fly to” field, fly to it and then read the coordinates.
Here’s the script that I use to get coordinates for addresses in AddressBook then export the results to a GPX file for loading into my GPS device.
tell application "Address Book"
set tmp to {}
set mySelection to selection
repeat with aPerson in mySelection
set theName to (first name of aPerson) & space & (last name of aPerson)
set _addresses to addresses of aPerson
log _addresses
repeat with anAddress in _addresses
tell anAddress
set theLabel to the label of anAddress
set theStreet to the street of anAddress
set theCity to the city of anAddress
set theState to the state of anAddress
set theZip to the zip of anAddress
set theCountry to the country of anAddress
end tell
end repeat
end repeat
end tell
tell application "Google Earth"
activate
set cmtLn to theStreet & ", " & theCity & ", " & theState & ", " & theZip & ", " & theCountry
set the clipboard to cmtLn
tell application "System Events" to tell (name of application processes whose frontmost is true) to keystroke "a" using command down -- highlight any text in the "Fly to" window
tell application "System Events" to tell (name of application processes whose frontmost is true) to keystroke "v" using command down
tell application "System Events" to tell (name of application processes whose frontmost is true) to keystroke return
delay 1
set {lat, long} to {latitude, longitude} of (GetViewInfo)
end tell
-- Write GPX file
set gpxFile to theName & ".GPX"
set gpxFileRef to (open for access file gpxFile with write permission)
set boundsLn to "<metadata>" & return & tab & "<bounds minlat=" & quote & lat & quote & " minlon=" & quote & long & quote & " maxlat=" & quote & lat & quote & " maxlon=" & quote & long & quote & "/>" & return & "</metadata>"
set wptLn to "<wpt " & "lat=" & quote & lat & quote & space & "lon=" & quote & long & quote & ">" -- create wpt line
set nameLn to tab & "<name>" & theName & "</name>"
set cmtLn to tab & "<cmt>" & cmtLn & "</cmt>"
set descLn to tab & "<desc>" & cmtLn & "</desc>"
if theLabel contains "home" then
set symLn to tab & "<sym>" & quote & "Residence" & quote & "</sym>"
else
set symLn to tab & "<sym>" & quote & "Waypoint" & quote & "</sym>"
end if
try
set eof gpxFileRef to 0
write "<gpx version=\"1.1\" creator=\"AB2GPX\"
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
xmlns=\"http://www.topografix.com/GPX/1/1\"
xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 [url=http://www.topografix.com/GPX/1/1/gpx.xsd\>]http://www.topografix.com/GPX/1/1/gpx.xsd\">[/url]
" & return & boundsLn & return & return & wptLn & return & nameLn & return & cmtLn & return & descLn & return & symLn & return & "</wpt>" & return & return & "</gpx>" to fileRef
on error error_message number error_number
display dialog error_message & return & error_number & return & "<gpx"
end try
Hope this helps.
Cheers, Tony
apsharman, thanks for your reply.
Try running this code and observe the error the Script Editor displays…
tell application "Google Earth"
set loc to ({latitude, longitude}) of (GetViewInfo)
set clipboard to loc
end tell
As you can see, Google Earth is able to send out the loc info, but for whatever reason AppleScript doesn’t want to toss it into the clipboard.
try…
tell application "Google Earth"
set loc to ({latitude, longitude}) of (GetViewInfo)
set the clipboard to loc
end tell
display dialog (the clipboard)'s item 1
display dialog (the clipboard)'s item 2
Thank you for the response clemhoff.
I guess my deffinition of “clipboard” is different then what I thought it meant under AppleScripting. I want to grab the loc and have it ready in my clipboard to be pasted into a different application (Lightroom 2 and Jeffry’s Geoencode Plug-In). Is there a different “clipboard” I need to define that’ll be accessible via the paste function of any application?
Thanks!