Newbie - Export Address Book pics as JPEG and send to Bluetooth

Hacked together something based upon other scripts I’ve seen. I can export to TIFF :smiley: , but fail to convert to JPEG. :frowning: Didn’t attempt sending to Bluetooth device yet. :confused: Gives an error message that it can’t get POSIX path of “/tmp/Name.jpg”. Any help is appreciated…


property myOutputDirectory : "/Users/Me/Desktop/Addresses"

set home to (do shell script "echo ~")
set imageDir to home & "/Library/Application Support/AddressBook/Images/"
set destinationDir to POSIX path of (choose folder with prompt "Choose an destination directory:")

tell application "Address Book"
	set thePeople to every person in group "T637"
	repeat with thePerson in thePeople
		if the name of thePerson exists then
			set theName to the name of thePerson
			if the image of thePerson exists then
				set theImage to the image of thePerson as TIFF picture
				set imageFile to my blankFile(theName & ".tiff")
				write theImage to imageFile as TIFF picture
				tell application "Image Events"
					set jpgFile to (POSIX path of ("/tmp/" & theName & ".jpg"))
					set tiffFile to open imageFile
					save theImage as JPEG in file jpgFile with icon
					close theImage
				end tell
			end if
		end if
	end repeat
end tell

on blankFile(filename)
	set filePath to (myOutputDirectory & "/" & filename) as POSIX file
	open for access filePath with write permission
	set eof of filePath to 0
	close access filePath
	return filePath as alias
end blankFile

Try using a directory in your home dir instead of tmp.

Thanks, that helped. Also figured out I was using a variable or two incorrectly. I now have that part fully working. Now to see if I can script the use of the Bluetooth device browser to copy the files over. :wink:


property myOutputDirectory : "/Users/wracz/Desktop/Addresses"

set home to (do shell script "echo ~")
set imageDir to home & "/Library/Application Support/AddressBook/Images/"
set destinationDir to POSIX path of (choose folder with prompt "Choose an destination directory:")

tell application "Address Book"
	set thePeople to every person in group "T637"
	repeat with thePerson in thePeople
		if the name of thePerson exists then
			set theName to the name of thePerson
			if the image of thePerson exists then
				set theImage to the image of thePerson as TIFF picture
				set imageFile to my blankFile(theName & ".tiff")
				write theImage to imageFile as TIFF picture
				tell application "Image Events"
					set jpgFile to (myOutputDirectory & "/" & theName & ".jpg")
					set tiffFile to open imageFile
					save tiffFile in file jpgFile as JPEG with icon
					close tiffFile
				end tell
			end if
		end if
	end repeat
end tell

on blankFile(filename)
	set filePath to (myOutputDirectory & "/" & filename) as POSIX file
	open for access filePath with write permission
	set eof of filePath to 0
	close access filePath
	return filePath as alias
end blankFile