AppleScript: Bild-Datein und PDFs weg sortieren…

Erst mal Danke an rumbleinthedesert für die Spende, für das Skript!
Damit lassen sich PDFs (und nunmehr auch Bilder) einfach sichten und weg sortieren. Man hat einen Ordner mit seinen Bildern, in diesem Ordner sind vielleicht schon mögliche Zielordner enthalten, ansonsten kann man im Verlauf des Skriptes auch neue Ordner anlegen lassen…
Zieht man nun diesen Ordner auf das unten gezeigte, als AppleScript-Programm gespeicherte Skript, öffnet es der Reihe nach die Bilder oder PDFs in der Vorschau, zeigt einem eine Liste der Zielordner an und man kann recht flott die Bilder weg sortieren. Ist dem Mail-Skript nicht unähnlich….
Code zum markieren einmal anklicken Code im Skript-Editor öffnen

on open thefolder

if (count of thefolder) = 1 then

tell application “Finder”

set thefolder to (item 1 of thefolder) as alias

set thefolder_posix to POSIX path of (thefolder as alias)

set sort_destis to name of every folder of thefolder

set thepdfs to every file of thefolder

repeat with thepdf in thepdfs

if name of thepdf ends with “.pdf” or name of thepdf ends with “.png” or name of thepdf ends with “.jpg” or name of thepdf ends with “.gif” or name of thepdf ends with “.psd” then

set thepdf_posix to POSIX path of (thepdf as alias)

do shell script “open -a /Applications/Preview.app ” & quoted form of thepdf_posix

tell me to activate

tell me to set thedesti to choose from list {“••NEW Folder••”} & sort_destis with prompt “In welchen Ordner verschieben?”

if thedesti as text = “••NEW Folder••” then

set newfoldername to “”

repeat until newfoldername ≠ “”

tell me to set newfoldername to text returned of (display dialog “Name of new Folder” default answer “”)

try

do shell script “cd ” & quoted form of thefolder_posix & “;mkdir ” & quoted form of newfoldername

end try

set thedesti to newfoldername

end repeat

end if

tell application “Preview”

activate

–kleiner Pfusch, weil die Vorschau keine AppleScript-Befehle kennt…

tell application “System Events”

keystroke “w” using command down

end tell

end tell

do shell script “mv ” & quoted form of thepdf_posix & ” ‘” & thefolder_posix & thedesti & “/” & my checkname_with_pdf_suffix(name of thepdf, ((thefolder & thedesti) as text) as alias, false) & “‘”

end if

end repeat

end tell

tell me to activate

tell me to display dialog “bin am Ende”

end if

end open

on checkname_with_pdf_suffix(n, D, looped)

tell application “Finder”

set thefiles to name of every item of (D as alias)

end tell

if thefiles contains n then

if looped = false then

set n to ((characters 1 through -5 of n) & ” 1″ & (characters -4 through -1 of n)) as text

my checkname_with_pdf_suffix(n, D, true)

else

set tmp to (last word of ((characters 1 through -5 of n) as text) as integer)

set tmpcount to (count of characters of (tmp as text)) + 5

set tmp to tmp + 1

set n to ((characters 1 through (-1 * tmpcount) of n) & tmp & (characters -4 through -1 of n)) as text

my checkname_with_pdf_suffix(n, D, true)

end if

else

return n

end if

end checkname_with_pdf_suffix

Leave a Reply