AppleScript Reste-Eintopf II
9/12/2011Add to Login-Items
--03.09.2008 hubionmac.com
--asks for an app and adds it to login items
addtologin(choose file of type {"APPL"})
on addtologin(thisApp) -- adds an item to login items
set appPath to POSIX path of thisApp
tell application "System Events"
set appName to name of thisApp
set shortName to (characters 1 through ((get offset of ".app" in appName) - 1) of appName) as text
if shortName is not in (name of every login item) then
make login item at end with properties {path:appPath}
end if
end tell
end addtologin
Nach Datei-Endungen sortieren
Das hatte ich mal als Ordner-Aktion für meinen Download-Ordner erdacht... seitdem es Spotlight gibt, hat der Drang Downloads zu sortieren deutlich nachgelassen ;-)--19.11.2006 hubionmac.com
--Ordneraktion die Dateien an Hand Ihrer Datei-Endung in Unter-Ordner sortiert
on adding folder items to derOrdner after receiving added_items
-- die Liste kann man gut erweitern
set endungmitordner to {".jpg;JPEGS", ".mov;Movies"}
repeat with k in endungmitordner
--damit kann man die Einträge aus der Liste gut in Ihre Bestandteile zerlegen
--Ist auch super um in Strings Teile zu ersetzen =)
set AppleScript's text item delimiters to ";"
set endung to text item 1 of k
set ordnername to text item 2 of k
set AppleScript's text item delimiters to ""
tell application "Finder"
set inhalt to every item of derOrdner
set itemcount to count of every item of inhalt
-- wenn in dem Ordner nix drin ist, soll er auch nix machen... lohnt ja nicht
if itemcount > 1 then
repeat with aitem in inhalt
--Die Anzahl der Buchstabe einer definierten Endung... damit ich am Ende auch weiß ob ich nach
-- .tiff oder .mov suchen muss
set endcount to (-1 * (count of every character of endung))
set itemname to name of aitem
if (characters endcount through -1 of itemname) as text = endung then
--wenn es den ordner schon gibt den fehler ignorieren und weiter im Text
try
make folder at derOrdner with properties {name:ordnername}
end try
--wir basteln uns einen Alias zu einem Verzeichnis
set workingdir to ((derOrdner as string) & ordnername & ":") as alias
--tja und dieser teil bewegt die Datei in den Ordner... und bennent sie um, sofern der
--Name bereits im Zielordner existiert
-- man könnte statt des counters auch die uhrzeit bzw. das datum nehmen...
-- oh ich neheme die Uhrzeit =).
try
move aitem to workingdir as alias
on error
set no_error to false
repeat until no_error = true
set counter to (time of (current date))
try
set name of aitem to (counter & "##" & itemname) as string
move aitem to workingdir as alias
set no_error to true
exit repeat
on error
set no_error to false
end try
end repeat
end try
end if
end repeat
end if
end tell
end repeat
end adding folder items to
Safari Bookmark Saver
Man nehme den Titel und die URL der aktuellen Seite und speichere sie via Skript in einer kleinen HTML-Datei (meta-refresh)... fertig ist das Platform-übergreifende Bookmark-File--18.01.2005
--Safari Bookmark safer
-- it's not a boookmark but a tiny html file that redirects to the saved URL
set html_text01 to "<html><meta http-equiv=\"refresh\" content=\"0; URL="
set html_text02 to "\"></html>"
tell application "Safari" to set windowcount to count of every window
if windowcount ≥ 1 then
tell application "Safari" to set theurl to URL of document 1
tell application "Safari" to set thename to name of document 1
display dialog "Filename" default answer thename
set thename to text returned of the result
set thetext to html_text01 & theurl & html_text02 as text
do shell script "echo " & quoted form of thetext & "|cat >~/Desktop/" & quoted form of thename & ".html"
end if
Folder-List
Erstelle eine Art Folder-Map... keine Ahnung wofür ich das mal brauchte...-- 18.3.2007 hubionmac.com.com
-- creates a table of contents (tree structure) of a folder that was dropped onto the script and saves it into a text file
global theroottxt, thefolder_unix, tabcount
on open thefolder
if (count of thefolder) > 1 then
display dialog "Please put ONE Folder onto the script"
end if
set thefolder to thefolder as alias
set thefolder_unix to POSIX path of thefolder
set theroottxt to thefolder as text
tell application "Finder"
set these_folders to every folder of thefolder
end tell
set tabcount to 0
repeat with this_folder in these_folders
set folderstring to get_folderstring(this_folder)
do shell script ("echo " & quoted form of folderstring & "|cat>> " & quoted form of thefolder_unix & "folder_list.txt") as text
do_folder(this_folder)
end repeat
end open
on do_folder(this_folder)
set tabcount to tabcount + 1
tell application "Finder"
set these_folders to every folder of this_folder
end tell
repeat with this_folder in these_folders
set folderstring to get_folderstring(this_folder)
do shell script ("echo " & quoted form of folderstring & "|cat>> " & quoted form of thefolder_unix & "folder_list.txt") as text
do_folder(this_folder)
end repeat
set tabcount to tabcount - 1
end do_folder
on get_folderstring(this_folder)
tell application "Finder"
set FolderName to name of this_folder
end tell
repeat with i from 1 to tabcount
set FolderName to tab & FolderName
end repeat
return FolderName as text
end get_folderstring
Rekursions-Beispiel
Würde ich heute ehr mit find -type d lösen, aber geht auch so--12.10.2005 hubionmac.com
--Beispiel zum Thema Rekursion
global folderkind
set thisfolder to choose folder
display dialog "deepcount=" default answer "0"
set deepcount to text returned of the result as integer
if deepcount = 0 then
process_item(thisfolder)
else
process_folder(thisfolder, deepcount)
end if
on process_folder(this_item, deepcount)
tell application "Finder"
set these_items to every folder of this_item
set deepcount to deepcount - 1
end tell
repeat with this_item in these_items
if deepcount = 0 then
process_item(this_item)
else
process_folder(this_item, deepcount)
end if
end repeat
end process_folder
on process_item(this_item)
tell application "Finder"
set itemname to name of this_item
display dialog itemname
end tell
end process_item


