Finder: Sortieren nach “Hinzugefügt am”

10/11/2010
Ich finde die Fächer-Darstellung beim Download-Ordner recht praktisch, gerade weil man dort Dateien nach dem Datum an dem sie zum Ordner hinzugefügt wurden sortieren kann. Leider fehlt dieses Information in der normalen Finder-Ansicht und lädt man sich eine Datei via FTP oder über andere Wege, stimmt das Änderungsdatum nicht zwingend mit dem Download-Datum überein. Bei macworld.com gibt es ein Beispiel für eine Ordneraktion,
die über den Automator erstellt wird. Dort wird jede hinzugefügt Datei einfach ange-touch-t und somit das Änderungsdatum auf das aktuelle Datum geändert. Eigentlich recht elegant dachte ich, nur halt eben nur so lange bis sich das Änderungsdatum mal ändert. Aus diesem Grund habe ich mir das Kommentar-Feld ausgesucht, in dem das Datum einfach als Text eingetragen wird, so bleibt das Hinzugefügt-am-datum auch nach einer Änderung der Datei erhalten.... Bis Apple das endlich mal als Feature mit einführt.
Code zum markieren einmal anklicken Code im Skript-Editor öffnen

on adding folder items to this_folder after receiving added_items

repeat with added_item in added_items

tell application "Finder"

set timestamp to do shell script "date '+%Y-%m-%d@%H:%M:%S'"

if (comment of added_item) as text = "" then

set comment of added_item to timestamp

end if

end tell

end repeat

end adding folder items to

Kleiner Tip zur Anwendung:

Das Skript ist als Ordner-Aktion gedacht, also als normales Skript im Ordner /Library/Scripts/Folder Action Scripts/ abspeichern und als Ordner-Aktion an den Download-Ordner anhängen... fertig

No Comments

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

AppleScript: Etwas eigenartige Datumsliste

25/02/2010
Es ging darum, eine Liste von Terminen zu bauen und zwar auf Grundlage von etwas eigenwillig formatierten Strings... wem auch immer das helfen mag =)
Code zum markieren einmal anklicken Code im Skript-Editor öffnen

--1/29

--2/22, 24, 26 (to return three different dates)

--2/22-25 (return four different dates)

--2/23-25, 27-28, 3/30 (return six different dates)

--2/21, 23, 25-27 (return five different dates)

--12/22-25, 1/1-2 works too =)

-- and even 1/25-2/1

set mydates to my makeDateList("1/25-2/1")

repeat with mydate in mydates

my addToiCal("MyDate2StringCalendar", mydate, mydate, "blaBla", "mydesc")

end repeat


------------------------------

on makeDateList(datestring)

set myoutput to {}

set AppleScript's text item delimiters to ","

set mydates to every text item of datestring

set AppleScript's text item delimiters to ","

set cd to (current date) - (time of (current date))

set day of cd to 1

set month of cd to 1

repeat with mydate_string in mydates

set mydate_string to delete_space(mydate_string as text)

if mydate_string contains "-" then

set AppleScript's text item delimiters to "-"

set StartDate to text item 1 of mydate_string

set EndDate to text item 2 of mydate_string

set AppleScript's text item delimiters to ""

copy string2date(StartDate, cd) to StartDate

copy string2date(EndDate, cd) to EndDate

copy {StartDate} to tempDateList

if StartDate < EndDate then

repeat until StartDate = EndDate

set StartDate to StartDate + 60 * 60 * 24

set tempDateList to tempDateList & StartDate

copy StartDate to cd

end repeat

set myoutput to myoutput & tempDateList

else

error "StartDate is not < EndDate!!"

end if

else

copy string2date(mydate_string, cd) to currentDate

set myoutput to myoutput & currentDate

end if

end repeat

return myoutput

end makeDateList


on delete_space(thestring)

repeat with i from 1 to count of characters of thestring

if last character of thestring = " " then

set thestring to (((characters 1 through -2 of thestring) as text) as text)

set is_modified to true

else

exit repeat

end if

end repeat

repeat with i from 1 to count of characters of thestring

if first character of thestring = " " then

set thestring to (((characters 2 through -1 of thestring) as text) as text)

set is_modified to true

else

exit repeat

end if

end repeat

return thestring

end delete_space


on string2date(thestring, datedummy)

--works with 23 or 1/12 (so day only or month/day)

copy datedummy to whereIStarted

if thestring contains "/" then

set AppleScript's text item delimiters to "/"

set theday to (text item 2 of thestring) as integer

set themonth to (text item 1 of thestring) as integer

set AppleScript's text item delimiters to ""

set month of datedummy to themonth

set day of datedummy to theday

-- if we started last year and should end up in next year... so what

if datedummy < whereIStarted then

set year of datedummy to (year of datedummy) + 1

end if

else

set theday to thestring as integer

set day of datedummy to theday

end if

return datedummy

end string2date


on addToiCal(CalendarTitle, StartDate, EndDate, mySummary, mydescription)

tell application "iCal"

if calendar CalendarTitle exists then

else

make new calendar with properties {name:CalendarTitle}

end if

tell calendar CalendarTitle

make new event at end of events with properties {start date:StartDate, end date:EndDate, summary:mySummary, description:mydescription, allday event:true}

end tell

end tell

end addToiCal


Kleines Update des Codes, da war noch ein Bug drin, der zu einem Endlos-Loop führen konnte...
Zudem ist das jetzt mal ein RealLive-Beispiel, mit Eintragung in iCal =)

No Comments

Wusste ich auch noch nicht String to AppleScript Date

23/09/2009
date "10.10.10"
date "Sonntag, 10. Oktober 2010 00:00:00"
ergibt doch glatt ein AppleScript-Datum...
No Comments

Unix Epoch Timestamp zu AppleScript Datum

20/03/2009
Ich wollte für ein Script Unix-Zeitstempel in ein Apple-Script-Datum konvertieren, und fand bei einer Suche diesen QuelleCode, der anscheinend nur unter englischen System funktioniert.... Nun, deshalb habe ich mir meine eigene AppleScript Routine geschrieben, die mir einfachen Mitteln einen Epoch-Zeitstempel in ein Applescript-Datum umwandelt:
Code zum markieren einmal anklicken

set einEpochString to do shell script "perl -e 'print time.\"\\n\";'" -- current epoch time as string


epoch2AppleScriptDate(einEpochString)


on epoch2AppleScriptDate(epoch_string)

set h to do shell script "date -r " & epoch_string & " \"+%Y %m %d %H %M %S\""

set mydate to current date

set year of mydate to (word 1 of h as integer)

set month of mydate to (word 2 of h as integer)

set day of mydate to (word 3 of h as integer)

set hours of mydate to (word 4 of h as integer)

set minutes of mydate to (word 5 of h as integer)

set seconds of mydate to (word 6 of h as integer)

return mydate

end epoch2AppleScriptDate

Update (10.11.2010)

Und heute wollte ich unbedingt via AppleScript einen Epoch-Zeitstempel erzeugen und fand hier folgendes:
Code zum markieren einmal anklicken Code im Skript-Editor öffnen

set nowSeconds to ((current date) - (date ("1/1/1970")) - (time to GMT)) as miles as string

No Comments