Fabolu
Gast
Hallo,
ich möchte einen Textstring suchen und ersetzen, ich habe jetzt schon so viele Vorschläge im Web gefunden, aber alle bekomme ich nicht implementiert.
Ziel ist es, die Kommentare von iPhoto zu verändern. Ich habe Kommentare an alle Fotos angehängt und möchte dies wieder löschen.
Vielen Dank schon einmal ...
Hier der korrigierte Code:
ich möchte einen Textstring suchen und ersetzen, ich habe jetzt schon so viele Vorschläge im Web gefunden, aber alle bekomme ich nicht implementiert.
Ziel ist es, die Kommentare von iPhoto zu verändern. Ich habe Kommentare an alle Fotos angehängt und möchte dies wieder löschen.
Vielen Dank schon einmal ...
Hier der korrigierte Code:
Code:
(* Search and Replace Comments within iPhoto.
This script should be placed in $HOME/Library/Scripts/Applications/iPhoto/
Fabian Stutzki, October 2007, adapted from Dan Lowe
*)
tell application "iPhoto"
activate
set photo_list to selection
(* If the first item in this list is an album, it's likely that we have no photos selected. Exit. *)
if class of item 1 of photo_list is album then
display dialog "You must select two or more photos before running this script." buttons {"Quit"} default button 1 with icon caution
return
end if
(* This script only makes sense if we have more than one photo selected. If fewer, exit. *)
if number of items of photo_list is less than 2 then
display dialog "You must select two or more photos before running this script." buttons {"Quit"} default button 1 with icon caution
return
end if
(* Get search string, which will be searched within the iPhoto comments *)
set search_text_dialog to display dialog "Enter a search string." default answer "" with icon note
set search_text to text returned of search_text_dialog
(* Is search string empty? *)
if search_text is "" then
display dialog "ERROR: You didn't enter a comment!" buttons {"Quit"} default button 1 with icon caution
return
end if
(* Get replace string, which will replace the search string. *)
set replace_text_dialog to display dialog "Enter a replace string, leave empty to delete search string." default answer "" with icon note
set replace_text to text returned of replace_text_dialog
(* Iterate over photos, then search and replace comments *)
repeat with the_photo in photo_list
set the_comment to comment of the_photo
set the_comment_replace to my replace_chars(the_comment, search_text, replace_text)
set comment of the_photo to the_comment_replace
end repeat
display dialog "Done!" buttons {"Quit"} default button 1 with icon note
end tell
on replace_chars(txt, srch, repl)
set AppleScript's text item delimiters to the srch
set the item_list to every text item of txt
set AppleScript's text item delimiters to the repl
set txt to the item_list as string
set AppleScript's text item delimiters to ""
return txt
end replace_chars
Zuletzt bearbeitet von einem Moderator: