Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the '10.3: A set of AppleScripts to toggle item visiblity' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.3: A set of AppleScripts to toggle item visiblity
Authored by: rulerk on Jan 08, '04 04:27:21AM

I am so glad someone posted this hint. I have been looking for something to do a thing like this for a few weeks now and found nothing. I've been trying to devise my own applescript using the file info commands in applescript, but apparently that is read-only. I discovered there were actually a few errors in the applescript that needed correcting and I have gone ahead and corrected them. The most worst error was with the way the POSIX path was being quoted and the fact that my iPod has an apostrophe in the name. That just killed the script outright. Anyway, it should work perfectly on just about any system now (remember, you need the developertools or at least Setfile). Oh and to the best of my reckoning, the ? that was hanging people up earlier should be a not equal sign (option-equal). That of course is fixed as well. If you find any more problems, post them.

Make Invisible
[code]
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 is not equal to 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 " & quoted form of POSIX path of this_item
else
do shell script "/Developer/Tools/SetFile -a V " & quoted form of POSIX path of this_item with administrator privileges
end if
end tell
end invis
[/code]

Make Visible
[code]
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 " & quoted form of POSIX path of this_item
else
do shell script "/Developer/Tools/SetFile -a v " & quoted form of 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
[/code]



[ Reply to This | # ]