Hallo Willem,
und hier ist der Knüller, welcher mir vorgeschwebt ist. :-)
Der folgende Code – als Applikation gespeichert – ergibt ein Droplet. Ich nenne es "OrdneraktOnOff_01d".
Dieser Name deutet an, dass es einem gedroppten Ordner ein Ordneraktions-Script anhängen oder das angehängte
entfernen kann. Die Etikettenfarbe des Ordners wird je nach Zustand auf "Grün" oder "Keine" gesetzt.
Es kommt noch besser: Wenn man ein Ordneraktions-Script auf das Droplet zieht, merkt sich dieses den Pfad
und hängt dem nächsten gedroppten (scriptfreien) Ordner dieses Script an.
Das ist noch nicht alles! :-) Ein Doppelklick auf das Droplet zeigt einen Dialog mit dem Pfad zum aktuellen
Ordneraktions-Script. Per Klick auf die Buttons kann der Anwender diesen Pfad bestätigen oder verlangen,
ein neues Script auszuwählen oder den Pfad zu entfernen. Wenn noch kein Script eingetragen ist, oder dieses
nicht gefunden werden kann, erscheint ein entsprechender Dialog.
---
property scriptPath : ""
on run
showConfig()
end run
on showConfig()
if scriptPath is not "" then
try
scriptPath as alias
set dR to button returned of (display dialog ¬
"Das aktuelle Ordneraktions-Script:
" & scriptPath buttons {"Entfernen", "Ändern", "OK"} default button 3 with icon 1)
if dR = "Ändern" then
modConfig()
else if dR = "Entfernen" then
set scriptPath to ""
end if
on error
with timeout of 300 seconds
set dR to button returned of (display dialog ¬
"Das aktuelle Ordneraktions-Script kann nicht gefunden werden." buttons ¬
{"Abbruch", "Auswählen"} default button 2 with icon 2)
if dR = "Auswählen" then
set scriptPath to (choose file of type "osas" with prompt "Ein Ordneraktions-Script wählen") as Unicode text
end if
end timeout
end try
else
set dR to button returned of (display dialog ¬
"Es ist kein Ordneraktions-Script bekannt." buttons {"Abbruch", "Auswählen"} default button 2 with icon 1)
if dR = "Auswählen" then
modConfig()
end if
end if
end showConfig
on modConfig()
with timeout of 300 seconds
set scriptPath to (choose file of type "osas" with prompt "Ein Ordneraktions-Script wählen") as Unicode text
end timeout
showConfig()
end modConfig
on open droppedObject
set folPath to item 1 of droppedObject as Unicode text
if folPath ends with ":" then
tell application "System Events"
set scriptList to attached scripts folPath
if scriptList is {} then
if scriptPath = "" then
tell application "Finder" to activate
with timeout of 300 seconds
set scriptPath to ¬
(choose file of type "osas" with prompt "Ein Ordneraktions-Script wählen") as Unicode text
end timeout
else
try
scriptPath as alias
on error
tell application "Finder" to activate
with timeout of 300 seconds
set dR to button returned of (display dialog ¬
"Das aktuelle Ordneraktions-Script kann nicht gefunden werden." buttons ¬
{"Abbruch", "Auswählen"} default button 2 with icon 2)
if dR = "Auswählen" then
set scriptPath to ¬
(choose file of type "osas" with prompt "Ein Ordneraktions-Script wählen") as Unicode text
end if
end timeout
end try
end if
attach action to folPath using scriptPath
set folStatus to true
else
repeat with i from (count of scriptList) to 1 by -1
remove action from folPath using action number i
end repeat
set folStatus to false
end if
end tell
if folStatus then
tell application "Finder" to set label index of folder folPath to 6
else
tell application "Finder" to set label index of folder folPath to 0
end if
else
if file type of (get info for file folPath) is "osas" then
set scriptPath to folPath
end if
end if
end open
---
Was fehlt noch? Erstens, die Prüfung, ob das gewählte Script an einem zulässigen Ort liegt (und somit als
Ordneraktion akzeptiert wird). Zweitens, ob es ein veritables Ordneraktions-Script ist. Und drittens, ob der Code
fehlerfrei funktioniert. Während der erste Punkt halbwegs zuverlässig eingebaut werden könnte, wird es ab dem
zweiten ziemlich schwierig. Doch sollte der Anwender auch etwas Eigenverantwortung zeigen ...
Gruss, Hans
als Antwort auf: [#419354]