Applescript: Modification/creation date verwursten

8/09/2010
Hier zwei Beispiele, was man so mit dem Änderungsdatum oder Erstellungsdatum von Dateien in Ordner so anstellen kann. Und der Auslöser...
Code zum markieren einmal anklicken Code im Skript-Editor öffnen

--hubionmac.com 08.09.2010

--set a folder's name to creation date of one of it's items...

--date string format 2010-01-01


set thefolder to choose folder

tell application "Finder"

set thedates to (creation date of every item of thefolder)

set item_dates to {}

repeat with a in thedates

if my make_dateString(a) is not in item_dates then

set item_dates to item_dates & my make_dateString(a)

end if

end repeat

-- wenn also dateien von mehr als einem Tag in dem ordner stecken...

if (count of item_dates) > 1 then

set item_dates to choose from list item_dates with prompt "Oje, welche Datum soll ich denn nur nehmen..."

end if

set current_foldername to name of thefolder

set string_to_add to text returned of (display dialog "Soll noch etwas an den Ordner-Namen angehängt werden?

\"" & item_dates & " " & current_foldername & "\"" default answer current_foldername)

set newfoldername to item_dates & " " & string_to_add as text

set comment of thefolder to "Alter Name: \"" & current_foldername & "\""

set name of thefolder to newfoldername

end tell


to make_dateString(thedate)

set themonth to characters -2 through -1 of ("0" & (month of thedate as integer) as text)

set theyear to year of thedate

set theday to characters -2 through -1 of ("0" & (day of thedate as integer) as text)

return theyear & "-" & themonth & "-" & theday as text

end make_dateString

Code zum markieren einmal anklicken Code im Skript-Editor öffnen

-- hubionmac.com 08.09.2010

--sets modification date of a folder to the latest modification date of its items


set thefolder to choose folder

tell application "Finder"

set thefiles to every item of thefolder

set thedates to (creation date of every item of thefolder)

set latest_date to modification date of item 1 of thefolder

repeat with i from 1 to (count of thefiles)

set current_item to item i of thefiles

if latest_date < (modification date of current_item) then

set latest_date to (modification date of (current_item as alias))

end if

end repeat

set modification date of thefolder to latest_date

end tell

Code zum markieren einmal anklicken Code im Skript-Editor öffnen

--hubionmac.com >~2007 i think

--AppleScript Droplet to sort fieles into folders by creation date

on open these_items

set thelist to {make_dateString(current date, 1)} & {make_dateString(current date, 2)} & {make_dateString(current date, 3)} as list

choose from list thelist with prompt "Choose date format:"

if result as text = item 1 of thelist as text then

set theformat to 1

else if result as text = item 2 of thelist as text then

set theformat to 2

else if result as text = item 3 of thelist as text then

set theformat to 3

end if

repeat with this_item in these_items

tell application "Finder"

-- set thedate to creation date of this_item

set thedate to modification date of this_item

set theLocation to quoted form of POSIX path of ((folder of this_item) as alias)

end tell

set foldername to make_dateString(thedate, theformat)

try

do shell script "cd " & theLocation & ";mkdir " & quoted form of foldername

end try

set the_item to quoted form of POSIX path of this_item

-- 2008-05-26 -n Option add, so files are not overwritten

do shell script "cd " & theLocation & ";mv -n " & the_item & " ./" & quoted form of foldername & "/"

end repeat

end open



on get_month_number(incomingDate)

-- works with systems <OS X 10.4

copy incomingDate to b

set the month of b to January

set month_number to "0" & (1 + (incomingDate - b + 1314864) div 2629728) as text

return (characters -2 through -1 of month_number) as text

end get_month_number


on make_dateString(thedate, theformat)

if theformat = 1 then

set theday to characters -2 through -1 of (("0" & day of thedate) as text) as text

set thestring to (year of thedate) & "-" & get_month_number(thedate) & "-" & theday

else if theformat = 2 then

set thestring to (year of thedate) & "-" & get_month_number(thedate)

else if theformat = 3 then

set thestring to (year of thedate)

end if

return thestring as text

end make_dateString



No Comments

Hubi’s Address Book Scripts

24/04/2010

Ich wurde von einem Leser dieses Blogs gebeten einige Skripte zu schreiben, da er sich seine Adressbuch-Datenbank mit vielen doppelten und Falschen Einträgen etwas zerschossen hatte. Dabei sind einige allgemeine Skripte entstanden, die ähnlich der iTunes Scripte einem Helfen das zu Skripten, was dass Apple Adressbuch nicht von selber tut. Dabei handelt es sich um ein Sammlung in der sich erstmal eine Skript-Bibliothek für häufig benutzt Funktionen angelegt habe.
Die Installation übernimmt ein kleines Script, welches auch gleich das AppleScript-Menü aktiviert, sofern noch nicht geschehen. Ich habe in die Library einen kleiner Version-Check eingebaut. Der (wenn nicht in den letzten 24h bereits geschehen) hier nachsieht, ob es eine neuere Version gibt. Bei dem Ding handelt es sich noch um die erste Version, also bitte Nachsicht und Fehler/Verbesserungen bitte gleich in Comments =)

Ich denke die Bezeichnungen der Skripte beschreiben deren jeweilige Funktionsweise wohl ausreichend =)

Update 16.01.2011

Ich habe die Bezeichnung der Skripte etwas verändert, hier und da etwas korrigiert, den Installer verbessert und eine Skript hinzugefügt, welches Duplikate in einer Gruppe sammelt.

Nur um das noch einmal klarzustellen:
Macht einen Backup eurer Adressen, die Nutzung der Skripte geschieht auf eigene Gefahr!!!

Die Skripte mit Installer also hier:

16 Comments

AppleScript: Bild-Datein und PDFs weg sortieren…

19/03/2010
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

No Comments

Hubi’s iTunes Scripts

13/12/2009
Das war eigentlich das erste Stück Software, das ich selber wirklich entwickelt habe. Ist auch heute noch ein treuer Helfer. Wenn Du also Deine iTunes Stücke sortieren möchtest, ID-Tags bereinigen oder neu organisieren möchtest. Dann können diese Scripte viel Zeit sparen =)
DOWNLOAD
Hubi's iTunes Skripts v.1.9
(3505 hits)
9 Comments

Mal flink Dateien im Finder verschieben

5/09/2009

Ich sortiere gerade meine zig Dateien und Ordner, die ich in den letzten Monaten angelegt habe. Ein Bild hier, ein nettes Tool dort... und hey, diesen Text wollte ich noch lesen.
Ich bezweifle, dass ich alles von dem Zeug noch brauchen werde, aber um wenigstens die paar Dinge wieder zu finden und halbwegs geordnet abzulegen, habe ich mir ein kleines Skript geschrieben,

mit dem ich die Auswahl im Finder in einen beliebigen Unterordner verschieben kann. Ggf. kann ich den auch noch darüber erstellen.

Das Ding habe ich mir jetzt über FastScripts auf einen Short-Cut gelegt und flux ist der der Finder um das Feature -> Bewege Auswahl in Unterordner XY reicher =)

Code zum markieren einmal anklicken oder Code im Skript-Editor öffnen

--hubionmac.com 05.09.2009

tell application "Finder"

set myfolder to container of ((item 1 of (selection as list)) as alias)

set folderlist to (name of every container of myfolder)

end tell

set selectionNames to getSelectionNames()

set folderlist to BubbleSort(folderlist)

set folderlist to {"----NewFolder----"} & CheckupLists(folderlist, selectionNames)

tell application "Finder"

set theaction to choose from list folderlist default items {item 1 of folderlist}

if theactionfalse then

if theaction as text = (item 1 of folderlist) as text then

set foldername to text returned of (display dialog "New folder name?" default answer "new folder")

set thefolder to make new folder at myfolder with properties {name:foldername}

move selection to thefolder

else

move selection to folder (theaction as text) of myfolder

end if

end if

end tell

on BubbleSort(theList)

if class of theList is list then

set theSize to length of theList

repeat with i from 1 to theSize

repeat with j from 2 to (theSize - i + 1)

if ((item (j - 1) of theList) > (item j of theList)) then

set temp to (item (j - 1) of theList)

set (item (j - 1) of theList) to (item j of theList)

set (item j of theList) to temp

end if

end repeat

end repeat

return theList

else

return false

end if

end BubbleSort

on getSelectionNames()

tell application "Finder"

set b to {}

repeat with a in (selection as list)

set b to b & name of a

end repeat

end tell

return b

end getSelectionNames

on CheckupLists(folderlist, selectionNames)

set ff to {}

repeat with f in folderlist

if selectionNames does not contain f then

set ff to ff & f

end if

end repeat

return ff

end CheckupLists

No Comments