About Iphoto

Everything Iphoto and Apple

Iphoto Applescripts

Posted by Rose Broyles On October - 31 - 2009
Apple Inc.
Image via Wikipedia

One of the great things about Apple products is that they are very user friendly. Everything is always ready to use out-of-the-box. You don’t have to be a technical guru to figure out how to double click on a picture to open up this or open up that. However, what would software be without technophiles who want to automate certain things or  make an application do something a little “extra”. Well, Apple has its own scripting language called Applescript. For all intents and purposes of this website, we will be talking about applescript for Iphoto in particular. Though this is not certainly all you can do, here a few useful ones you can check out. I’m sure I’ll be updating this page as I find more scripts, but I haven’t had a chance try all of them so comment below to let me know any of them are worthwhile!

Iphoto ‘09

Reverse geocode using Applescript

This one works with Iphoto and Google Earth. Select a photo that has a location associated with it — GPS related date or one you have chosen from within iPhoto, then run the script.

Shows you where photo was taken

(*
iPhoto to Google Earth lookup

Version: 1.0
Date: 2009-6-5
By: Adam Burt – a.burt@mac.com
Tested on: Mac OS 10.5.7 – iPhoto 8.0.3 – Google Earth 5 or above

Distributed under a Creative Commons Attributionb-NonCommerical-ShareAlike license:
http://creativecommons.org/licenses/by-nc-sa/2.0/uk/

Being dyslexic you might find my spelling some what creative.

What this is:
This script will shows the photo location with in Google Earth, if your photo has GPS data or has been added to a location with in iPhoto.

How to use:
1. Start up iPhoto

2. Select a photo that you know has GPS data or you have assigned a location to with in iPhoto.

3. Click the green “Run” button above and your photo should aper with in Google Earth.
*)

(*
NO WARRANTY :

BECAUSE THIS SCRIPT IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SCRIPT, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SCRIPT AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SCRIPT IS WITH YOU. SHOULD THE SCRIPT PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SCRIPT AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SCRIPT(INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SCRIPT TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*)

try

tell application “iPhoto”

– Getting current selected photo
set myImage to the selection
set myLongitude to «class lngt» of item 1 of myImage as string
set myLatitude to «class lati» of item 1 of myImage as string
set myDistance to «class alti» of item 1 of myImage as string

– Test for geo data with in the image!
if myDistance = “1.797693134862E+308″ then set myDistance to 140

if myLongitude is not “3.402823466385E+38″ and myLatitude is not “3.402823466385E+38″ then

– Tell google earth to show that location
tell application “Google Earth”
SetViewInfo {latitude:myLatitude, longitude:myLongitude, distance:myDistance, tilt:45, azimuth:24} speed 0.1
end tell

else
activate
beep
display dialog “Sorry your photo has no Geo Data embedded with in it.” with title “No Geo Data:” with icon stop
end if

end tell

on error
activate
beep
display dialog “Sorry it looks like you do not have a photo selected.” with title “Opps” with icon stop
end try

This script will link to a  photo within your iPhoto library and display it and its location as well within Google Earth

(*
iPhoto to Google Earth – Photo

Version: 1.0
Date: 2009-6-5
By: Adam Burt – a.burt@mac.com
Tested on: Mac OS 10.5.7 – iPhoto 8.0.3 – Google Earth 5 or above

Distributed under a Creative Commons Attributionb-NonCommerical-ShareAlike license:
http://creativecommons.org/licenses/by-nc-sa/2.0/uk/

Being dyslexic you might find my spelling some what creative.

What this is:
A script shows the location and  photo with in Google Earth from iPhoto, if your photo has GPS data or has been added to a location with in iPhoto.

How to use:
1. Start up iPhoto

2. Select a photo that you know has GPS data or you have assigned a location to with in iPhoto.

3. Click the green “Run” button above and your photo should aper with in Google Earth.
*)

(*
NO WARRANTY :

BECAUSE THIS SCRIPT IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SCRIPT, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SCRIPT AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SCRIPT IS WITH YOU. SHOULD THE SCRIPT PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SCRIPT AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SCRIPT(INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SCRIPT TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*)

tell application “iPhoto”

try

– Getting current data selected photo
set myImage to the selection
set myLongitude to «class lngt» of item 1 of myImage as string
set myLatitude to «class lati» of item 1 of myImage as string
set myDistance to «class alti» of item 1 of myImage as string
set myTitle to title of item 1 of myImage as string
set myFile to image path of item 1 of myImage as string
set myComment to comment of item 1 of myImage as string

– Test for geo data with in the image!
if myDistance = “1.797693134862E+308″ then set myDistance to 0

if myLongitude is not “3.402823466385E+38″ and myLatitude is not “3.402823466385E+38″ then
my geFile(myLongitude, myLatitude, myDistance, myTitle, myComment, myFile)
else
activate
beep
display dialog “Sorry your photo has no Geo Data embedded with in it.” with title “No Geo Data:” with icon stop
end if

on error
activate
beep
display dialog “Sorry it looks like you do not have a photo selected with in iPhoto.” with title “Opps” with icon stop
end try

end tell

on geFile(myLongitude, myLatitude, myDistance, myTitle, myComment, myFile)

set googelEathPath to path to application “Google Earth”
set googelEathPath to POSIX path of googelEathPath

set kmlHeder to “<?xml version=\”1.0\” encoding=\”UTF-8\”?>” & return & “<kml xmlns=\”http://www.opengis.net/kml/2.2\” xmlns:gx=\”http://www.google.com/kml/ext/2.2\” xmlns:kml=\”http://www.opengis.net/kml/2.2\” xmlns:atom=\”http://www.w3.org/2005/Atom\”>” & return & “<PhotoOverlay>” & return

set kmlName to tab & “<name>” & myTitle & “</name>” & return

if myComment = “” then
set kmldescription to “”
else
set kmldescription to tab & “<description>” & myComment & “</description>” & return
end if

set kmlCamera to tab & “<Camera>” & return & tab & tab & “<longitude>” & myLongitude & “</longitude>” & return & tab & tab & “<latitude>” & myLatitude & “</latitude>” & return & tab & tab & “<altitude>250</altitude>” & return & tab & tab & “<heading>24</heading>” & return & tab & tab & “<tilt>45</tilt>” & return & tab & tab & “<roll>2</roll>” & return & tab & “</Camera>” & return

set kmlStyle to tab & “<Style>” & return & tab & tab & “<IconStyle>” & return & tab & tab & tab & “<Icon>” & return & tab & tab & tab & tab & “<href>” & googelEathPath & “Contents/Resources/camera_mode.png</href>” & return & tab & tab & tab & “</Icon>” & return & tab & tab & “</IconStyle>” & return & tab & tab & “<ListStyle>” & return & tab & tab & tab & “<listItemType>check</listItemType>” & return & tab & tab & tab & “<ItemIcon>” & return & tab & tab & tab & tab & “<state>open closed error fetching0 fetching1 fetching2</state>” & return & tab & tab & tab & “<href>http://maps.google.com/mapfiles/kml/shapes/camera-lv.png</href>” & return & tab & tab & “</ItemIcon>” & return & tab & tab & “<bgColor>00ffffff</bgColor>” & return & tab & tab & “<maxSnippetLines>2</maxSnippetLines>” & return & tab & tab & “</ListStyle>” & return & tab & “</Style>” & return

set kmlImage to tab & “<Icon>” & return & tab & tab & “<href>” & myFile & “</href>” & return & tab & “</Icon>” & return

set kmlViewVolume to tab & “<ViewVolume>” & return & tab & tab & “<leftFov>-25</leftFov>” & return & tab & tab & “<rightFov>25</rightFov>” & return & tab & tab & “<bottomFov>-19.275</bottomFov>” & return & tab & tab & “<topFov>19.275</topFov>” & return & tab & tab & “<near>30.2365</near>” & return & tab & “</ViewVolume>” & return

set kmlPoint to tab & “<Point>” & return & tab & tab & “<altitudeMode>relativeToGround</altitudeMode>” & return & tab & tab & “<coordinates>” & myLongitude & “,” & myLatitude & “,” & myDistance & “</coordinates>” & return & tab & “</Point>” & return

set kmlFoter to “</PhotoOverlay>” & return & “</kml>”

– Crate Google Earth file and open it
set photoKml to (path to temporary items folder as string) & myTitle & “.kml”
set f to open for access photoKml with write permission
set eof f to 0

write kmlHeder & kmlName & kmldescription & kmlCamera & kmlStyle & kmlImage & kmlViewVolume & kmlPoint & kmlFoter to f

close access f

tell application “Google Earth”
open file photoKml
end tell

end geFile

Reverse geocode an image without Lat & Long data

tell application “iPhoto”
set myImage to the selection
tell myImage
set altitude of item 1 of myImage to 23 — In meters.
set longitude of item 1 of myImage to 0.003976
set latitude of item 1 of myImage to 51.397592
reverse geocode of item 1 of myImage
end tell
end tell

To reverse geocode an image with Lat & Long data

tell application “iPhoto”
set myImage to the selection
tell myImage to reverse geocode of item 1 of myImage
end tell

Find out more


Iphoto ‘08

Create a keyboard shortcut for All Events

tell application "iPhoto"
  activate
  select album "photos"
  tell application "System Events" to tell process "iPhoto"
    delay 0.25
    key code 48 --tab
    key code 126 --up arrow
    key code 5 --G scroll selected event into view
  end tell
end tell

Find out more

All Versions? (Not stated but definitely ‘08 and ‘09)

Iphoto to Photoshop

This is a simple script that allows a picture from Iphoto to be opened from Photoshop.


tell application “iPhoto”
activate
try
set the view to organize
copy (my selected_images()) to these_images
if these_images is false then error “Please select some images before using this script.”
set these_files to {}
repeat with i from 1 to the count of these_images
set this_image to item i of these_images
– get image paths and convert POSIX paths to alias references
set this_file to the image path of this_image
set this_file to (this_file as POSIX file) as alias
set the end of these_files to this_file
end repeat
on error error_message number error_number
if the error_number is not -128 then
display dialog error_message buttons {”OK”} default button 1
end if
return “user cancelled”
end try

end tell

tell application “Adobe Photoshop CS3″
activate
try
repeat with i from 1 to the count of these_files
set this_file to item i of these_files
open this_file
end repeat
on error error_message
display dialog error_message buttons {”Cancel”} default button 1
end try
end tell

on selected_images()
tell application “iPhoto”
try
– get selection
set these_items to the selection
– check for single album selected
if the class of item 1 of these_items is album then error
– return the list of selected photos
return these_items
on error
return false
end try
end tell
end selected_images

Reblog this post [with Zemanta]
  • Share/Bookmark

Leave a Reply

Most Commented

  • Recommended Book

VIDEO

TAG CLOUD

Sponsors

Rose's Random Twitter Updates

    © 2009-2010 About Iphoto