Want to highlight a helpful answer? Upvote!

Did someone help you, or did an answer or User Tip resolve your issue? Upvote by selecting the upvote arrow. Your feedback helps others! Learn more about when to upvote >

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

AppleScript for address book text delimiter issue

In the following code, it should parse out the gps values from a map URL in my contacts, and save them one by one to a .csv file. Everything works, except there seem to be an issue with my text delimiters not pulling out the correct data. The URL in each contact is exactly the same as this example, only with different numbers:

maps:II=&q=30.34562,-92.41811


So I changed applescript's text delimiters to "q=", and figured the 2nd word would be "30.34562,-92.41811" which is what I need. but it's giving me other data like the two II's. Here's the complete code:


display dialog "This script will find GPS data in your contacts (in the URL field) and export it for Garmin's poiLoader to transfer to a GPS device. House numbers are included." buttons {"Continue"} with title "Export GPS data for GARMIN"set tid to AppleScript's text item delimitersset AppleScript's text item delimiters to " "set theTotal to 0tell application "Contacts" set _groups to name of every group set theirGroup to choose from list _groups with title "EXPORTING GPS DATA" with prompt "Select an Address Book Group" if theirGroup is false then say "No group selected. Goodbye" return end if set theirGroup to theirGroup as string
set theContacts to (every person in group theirGroup) repeat with thePerson in theContacts set theData to "" set theGPSdata to "" set theWord to "" set theNumber to "" set theStreet to "" set theName to name of thePerson repeat with theURL in (every url of thePerson whose label is "gps") --maps:II=&q=30.34562,-92.41811 set theData to value of theURL set AppleScript's text item delimiters to "q=" set theGPSdata to the second word of theData set AppleScript's text item delimiters to "" end repeat repeat with this_address in (every address of thePerson whose label is "home") set theStreet to street of this_address try set theWord to the first word in theStreet on error --display dialog "There is no street address for " & theName end try
try set theNumber to theWord as integer --will just be the house number end try end repeat if theGPSdata is not "" then if theNumber is not "" then set theName to theName & " #" & theNumber end if set theData to theGPSdata & "," & theName do shell script "echo " & quoted form of theData & " >> ~/Desktop/theFile.csv" set theTotal to theTotal + 1 end if end repeatend tellset theData to ""set AppleScript's text item delimiters to tidsay "We are all finished exporting your GPS data. It is ready for Garmin's POI Loader."display dialog "All Done. Number of contacts with GPS data: " & theTotal

Mac OS X (10.7.3)

Posted on Nov 13, 2017 3:54 PM

Reply
Question marked as Best reply

Posted on Nov 13, 2017 4:41 PM

Hi SouthernAtHeart,


Try


second text item of theURL


rather then "second word".


Cheers,


H

1 reply

There are no replies.

AppleScript for address book text delimiter issue

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.