Objekte sichtbar/unsichtbar machen via AppleScript

Mittwoch, 26 November 2003
0.0/5 Bewertung (0 Stimmen)
Beschreibung

Ich habe schon oft gesehen, das SetFile herumgereicht wird als [U]das[/U] Tool um Dateien im Finder unsichtbar bzw. sichtbar zu machen (neben anderen Möglichkeiten), aber bisher noch Niemanden, der diese Funktion in ein nettes AppleScript integriert hat. Bitte beachten Sie, dass folgende Skripts SetFile benötigen, welches nur mit den Developer Tools ausgeliefert wird. Ich musste das Skript etwas anpassen, um es unter ”Panther” lauffähig zu machen, daher glaube ich nicht, dass es, wenn überhaupt, fehlerfrei unter ”Jaguar” läuft.
Das erste Skript (unsichtbar machen) macht einfach die aktuelle Finder-Auswahl unsichtbar. Falls Sie den Befehl ohne Bestätigung ausführen möchten, ändern Sie das safe_user Flag von true zu false. Das zweite Skript (sichtbar machen) öffnet eine Dialogbox mit einer Liste aller unsichtbaren Dateien des aktiven Finder-Fensters. Markieren Sie einfach jene, die Sie sichtbar machen möchten. Dieser Skript läuft sehr langsam, wenn der entsprechende Ordner viele Objekte beinhaltet - falls jemand Vorschläge hat, wie man die Geschwindigkeit verbessern könnte, wäre ich ihm sehr dankbar.
Legen Sie diese Skripts in das Verzeichnis ~/Library/Scripts/Applications/Finder, damit sie im Skript-Menü angezeigt werden, sobald der Finder im Vordergrund ist.
Persönlich nutze ich diese Skripts um den Programm-Ordner nach meinen Wünschen zu organisieren, ohne die Apple-Applikationen zu verschieben. Möglicherweise ist das jetzt nicht mehr nötig, aber ich habe bisher noch nichts Gegenteiliges gehört. Einfach ausgedrückt erzeuge ich von jeder iApplikation ein Alias und lege es in einen Unterordner namens, sagen wir, ”iApps”. Anschliessend mache ich das Programm selber unsichtbar und reduziere dadurch die Anzahl Objekte in meinem Programm-Ordner. Hurrah!
Unsichtbar machen:
-- Applescript: Make Invisible
-- For Mac OS X 10.3 Panther
-- This script is intended to be run from the scripts menu.
-- Its function is to set files to be invisible. To make
-- invisible: select some files to be made invisible. Run the
-- script. Enter your admin password if you are not the
-- owner of the files.
-- Will Robertson Nov 2003
property safe_user : false
-- Change this to your username:
tell application ”Finder”
set user to the system attribute ”USER”
set selec to the selection
set N to the number of items in selec
set proceed_flag to false

if safe_user then
set selec_names to {}

repeat with ii from 1 to the count of selec
if ii ? 1 then
set the end of selec_names to ”; ”
end if
set the end of selec_names to ¬
(the name of item ii of selec) as string
end repeat

if the button returned of (display dialog ¬
(”Make the following items in the current folder invisible?” & ¬
return & return & selec_names as string) buttons ¬
{”Make invisible”, ”Cancel”} default button ¬
”Cancel”) is ”Make invisible” then
set proceed_flag to true
end if
else
set proceed_flag to true
end if

if N > 0 then
-- THERE IS A SELECTION: Make it/them INVISIBLE
repeat with ii from 1 to N
set this_item to (item ii of selec as alias)
my invis(this_item, user) -- subroutine to make item invisible
end repeat
if N = 1 then
say ”Item made invisible”
else
say ”Items made invisible”
end if
else
say ”No items are selected”
end if
end tell
-- Subroutine to make an item (file or folder) invisible:
on invis(this_item, user)
tell application ”Finder”
if the owner of item this_item is user then
do shell script ”/Developer/Tools/SetFile -a V ”” & ¬
POSIX path of this_item & ”””
else
do shell script ”/Developer/Tools/SetFile -a V ”” & ¬
POSIX path of this_item & ””” with administrator privileges
end if
end tell
end invis

Sichtbar machen:
-- Applescript: Make visible
-- For Mac OS X 10.3 Panther
-- The function of this script is to remove invisibility from
-- items. Note it does not work with files that begin with a
-- dot (ie .DS_store), because those files are not shown in
-- the Finder, invisible or not.
-- Will Robertson Nov 2003
set the item_choices to {}
set the target_items to {}
set user to the system attribute ”USER”
tell application ”Finder”

set the target_folder to the folder of the front window as alias

set item_names to list folder (the target_folder) with invisibles
repeat with ii from 1 to the count of the item_names
if (the visible of the (info for ((target_folder as string) & ¬
(item ii of the item_names) as alias)) is false) and ¬
(the first item of (item ii of the item_names as string) ¬
is not ”.”) then
set the end of the item_choices to item ii of the item_names
end if
end repeat

if the number of items of item_choices is 0 then
display dialog (”No invisible files in the selected folder:” & return & ¬
POSIX path of target_folder as string) buttons ”OK” default button ”OK”
else
set the chosen_files to choose from list item_choices with prompt ¬
(”Choose item(s) to make visible in:” & return & POSIX path of ¬
target_folder as string) with multiple selections allowed
if the result is not false then
repeat with ii from 1 to the count of the chosen_files
set this_item to (target_folder as string) & (item ii of the ¬
chosen_files) as alias
if the owner of this_item is user then
do shell script ”/Developer/Tools/SetFile -a v ”” & ¬
POSIX path of this_item & ”””
else
do shell script ”/Developer/Tools/SetFile -a v ”” & ¬
POSIX path of this_item & ””” with administrator privileges
end if
end repeat

display dialog ¬
”The Finder will have to be relaunched in order to view these files. Do that now?” buttons ¬
{”Relaunch”, ”Not now”} default button ”Not Now”
if the button returned of the result is ”Relaunch” then
tell application ”Finder” to quit
delay 1
tell application ”Finder” to launch
end if
end if
end if
end tell

Spezifikationen

Hits

1117

© by macjaner.ch | Powered by GoeGG-ArT.ch