Ich räume gerade meine AppleScript-Verzeichnis auf und dabei sind mir einige Code-Schnipsel untergekommen, die noch nicht hier "archiviert" wurden:
convert aliases into symlinks:
Damit lassen sich wunderbar Aliase in symbolische Links umwandeln. Macht z.B. Sinn, wenn man schnell via Finder Aliase anlegt, die Software, die aber die Dateien braucht nur mit symbolischen Links klar kommt.
set thefolder to choose folder
set thefolderx to POSIX path of (thefolder as alias)
tell application "Finder"
set thealiases to every alias file of thefolder
repeat with thisalias in thealiases
set aliasname to name of thisalias
set theorig to original item of thisalias
set theorigx to POSIX path of (theorig as alias)
do shell script "cd " & quoted form of thefolderx & ";rm " & quoted form of aliasname & ";ln -s " & quoted form of theorigx & " " & quoted form of aliasname
end repeat
end tell
DropTar:
Ich wollte wohl mal via Drag&Drop bzw. eine Finder-Auswahl einfach als .tar.gz packen.... hat sich dank LaunchBar bei mir nun erledigt (da ist so etwas schon eingebaut), der Code landet nun hier
on open these_items
my makeTar(these_items)
end open
on run
tell application "Finder"
set these_items to selection
if these_items = {} then error "Nothing slected"
my makeTar(these_items)
end tell
end run
on makeTar(these_items)
-- READ THE NAME
display dialog "Name of the file:" default answer "" buttons {".TAR", ".TAR.GZ", "cancel"}
copy result as list to dialog01
set tarname to item 1 of dialog01
if tarname = "" then
display dialog "please enter a propper name!" buttons {"cancel"}
else
if (item 2 of dialog01) as text = ".TAR" then
set tarname to (tarname & ".tar") as text
set zz to "-"
else if (item 2 of dialog01) as text = ".TAR.GZ" then
set tarname to (tarname & ".tar.gz") as text
set zz to "-z"
end if
end if
-- READ THE LOCATION WHERE THE FILE SHOULD BE STORED
set save_path to POSIX path of (choose folder with prompt "Where do you wanna save " & tarname & "?")
set thefiles to ""
set first_item to true
repeat with this_item in these_items
tell application "Finder"
-- READ THE FILE's LOCATIONS AND COMPARE THEM
set current_container to container of this_item
if first_item = true then
set item_container to current_container
set first_item to false
end if
-- if the current_containter does not match the general container ERROR!
if item_container ≠ current_container then
display dialog "Sorry, this script can only proccess files/folders that at the same location" buttons {"cancel"}
else
-- GET THE ITEMS' NAMES AND LIST THEM
set item_name to name of this_item
set thefiles to thefiles & " \"" & item_name & "\""
end if
end tell
end repeat
-- GET THE POSIX PATH OF THE ITEMS ' CONTAINER
set thefilespath to quoted form of POSIX path of (item_container as alias)
-- MAKE THE COMMAND STRING FOR THE SHELL
set theshellcommand to ("cd " & thefilespath & "; tar " & zz & "cf " & quoted form of ((save_path & tarname) as text) & thefiles) as text
set the clipboard to theshellcommand
-- display dialog theshellcommand
-- DO THE SHELL COMMAND, BECAUSE THIS COULD TAKE SOME TIME... A LONG TIMEOUT SO NO APPLE EVENT TIMEOUT POPS UP =)
with timeout of 3600 seconds
do shell script theshellcommand
end timeout
end makeTar
dmg-maker:
Und hier wollte ich mal per AppleScript ein dmg-Image erstellen...
on open these_
if (count of these_) > 1 then
tell me to quit
end if
tell application "Finder"
set orig_image to quoted form of (POSIX path of item 1 of these_)
set imagename to quoted form of ((name of (item 1 of these_)) as text)
set image_destination to quoted form of POSIX path of (folder of ((item 1 of these_) as alias) as alias)
end tell
set thecommand to ("hdiutil convert " & orig_image & " -format UDZO -imagekey zlinb-level=9 -o " & image_destination & imagename & ".dmg") as text
tell application "Terminal"
run
delay 1
do script with command thecommand
end tell
end open
delete empty folders
Leere Ordner haben mit dem Code fast nichts zu lachen... funktioniert auch nur auf einer Ebene ist also nicht rekursiv geschrieben
on open hubi
tell application "Finder"
set folderkind to kind of folder 1 of startup disk
repeat with k in hubi
if kind of k = folderkind then
set itemcount to count of every item of k
if itemcount = 0 then
delete k
end if
end if
end repeat
end tell
end open
tell application "Finder"
set hubi to selection
set folderkind to kind of folder 1 of startup disk
repeat with k in hubi
if kind of k = folderkind then
set itemcount to count of every item of k
if itemcount = 0 then
delete k
end if
end if
end repeat
end tell
delete n chars at beginning/end of filename
tell application "Finder"
set hubi to selection
set folderkind to kind of folder 1 of startup disk
repeat with k in hubi
if kind of k = folderkind then
set itemcount to count of every item of k
if itemcount = 0 then
delete k
end if
end if
end repeat
end tell
delete .DS_Store
Die Dateien machen oft so gar keinen Sinn und stören mich einfach unter Windows.
set thepath to POSIX path of (choose folder)
set hubi to do shell script "cd " & quoted form of thepath & ";find ./ -name .DS_Store -delete"
display dialog ".DS_Store deleted"
Dateien nach Erstellungsdatum in Ordner sortieren
Ich glaube das war mal ein Versuch meinen Download-Ordner etwas aufgeräumter aussehen zu lassen... alles nur Schein ;-)
--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
Rechner ausschalten nach x-Minuten
Das funktioniert, wenn kein Dialog aufgeht... ansonsten müsste man das mit shutdown -now und Admin-Rechten machen...
with timeout of 600000 seconds
display dialog "Shutdown in x Minutes?" default answer 10
set i to (text returned of the result) as integer
delay i * 60
tell application "Finder" to shut down
end timeout