wiki:AppleAddressBookDatasource

Version 10 (modified by nadeem, 18 years ago) (diff)

--

How to convert the apple address book to RDF

These tools exist to do it:

Sources: Libby Miller, This blog entry.

Documentation by Apple

An applescript file that does a starting thing

tell application "Address Book"
	set out to "<rdf:RDF xmlns:foaf='http://xmlns.com/foaf/0.1/' xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'>"
	repeat with p in people
		set out to out & "<foaf:Person>"
		set out to out & "<foaf:name>" & (name of p) & "</foaf:name>"
		repeat with e in emails of p
			set out to out & "<foaf:mbox>mailto:" & value of e & "</foaf:mbox>"
		end repeat
		set out to out & "</foaf:Person>"
	end repeat
	set out to out & "</rdf:RDF>"
	out
end tell

The DataSource itself

It should copy/paste from the RDF-File datasource


I uploaded a script I made a couple of years ago, but it's appeared as 0 bytes. So here's the script. To use it, you need to create a group called "FOAF" and add anyone you want in your knows list to that group. If you have a URL for their FOAF file, select their card in the Address Book, choose Card>Add Field>URL, change the URL title to FOAF and but the URL in the URL box.

property foaf : "FOAF"

tell application "Address Book"
set m to properties of my card
set the_file to (((path to desktop) as string) & first name of m & last name of m & ".rdf") as file specification
set rdf to "<rdf:RDF" & return
set rdf to rdf & "xmlns:rdf=" & quote & "http://www.w3.org/1999/02/22-rdf-syntax-ns#" & quote & return
set rdf to rdf & "xmlns:rdfs=" & quote & "http://www.w3.org/2000/01/rdf-schema#" & quote & return
set rdf to rdf & "xmlns:foaf=" & quote & "http://xmlns.com/foaf/0.1/" & quote & return
set rdf to rdf & "xmlns:admin=" & quote & "http://webns.net/mvcb/" & quote & ">" & return
set rdf to rdf & "<foaf:Person rdf:nodeID=" & quote & "me" & quote & ">" & return
set rdf to rdf & "<foaf:name>" & first name of m & " " & last name of m & "</foaf:name>" & return
if nickname of m ≠ "" then
 set rdf to rdf & "<foaf:nick>" & nickname of m & "</foaf:nick>" & return
end if
if group foaf exists then
	repeat with this_person in every person of group foaf
		set rdf to rdf & "<foaf:Person>" & return
		set rdf to rdf & "<foaf:name>" & first name of this_person & " " & last name of this_person & "</foaf:name>" & return
		repeat with e in emails of this_person
			set rdf to rdf & "<foaf:mbox>mailto:" & value of e & "</foaf:mbox>" & return
		end repeat
	if ((count of urls of this_person) > 0) then
		if label of url 1 of this_person is "FOAF" then
			set rdf to rdf & "<rdfs:seeAlso rdf:resource=" & quote & value of url 1 of this_person & quote & "/>" & return
		end if
	end if
	set rdf to rdf & "</foaf:Person>" & return
	end repeat
	end if
	set rdf to rdf & "</rdf:RDF>"
end tell

try
	open for access the_file with write permission
	set eof of the_file to 0
	write (rdf) to the_file starting at eof
	close access the_file
on error
	try
		close access the_file
	end try
end try

Attachments (1)

Download all attachments as: .zip