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

10.3: A set of AppleScripts to toggle item visiblity Desktop
Well, I've seen SetFile mentioned around as the tool for making files visible and invisible in the Finder (among other things), but no-one seems to have wrapped it up nicely in an Applescript. Note the following scripts require SetFile, which is only included in the Developer Tools. Unfortunately, I have nowhere to post these so I'll simply have to paste them in here. Also, I had to change them to work with Panther; hence, I don't think they will work reliably (if at all) in Jaguar.

The first script (Make Invisible) simply makes the current Finder selection invisible. If you don't want confirmation every time you run it, change the safe_user flag from true to false. The second script (Make Visible) brings up a dialog box listing all invisible files in the front window. Simply choose the ones you want to be made visible. This script is very slow in folders with many items -- if anyone can suggest speed improvements I'd be most grateful.

I use these scripts to rearrange my Applications folder without moving any Apple apps. This is probably unnecessary now, but I haven't heard one way or another and I'm too lazy to do testing. Basically what I do is make an alias of each of the iApps, say, and put them in an iApps folder. Then I can make the Applications themselves invisible and cut down the number of items in my Applications folder. Hurrah!

Read the rest of the article for the scripts...

Make Invisible:

-- 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
Make Visible:

-- 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
Put these scripts in the folder ~/Library -> Scripts -> Applications -> Finder for them to appear in the Script menu when the Finder is the frontmost app. I use these scripts to rearrange my Applications folder without moving any Apple apps. This is probably unnecessary now, but I haven't heard one way or another and I'm too lazy to do testing. Basically what I do is make an alias of each of the iApps, say, and put them in an iApps folder. Then I can make the Applications themselves invisible and cut down the number of items in my Applications folder. Hurrah!
    •    
  • Currently 1.50 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (4 votes cast)
 
[13,492 views]  

10.3: A set of AppleScripts to toggle item visiblity | 6 comments | Create New Account
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: marky on Nov 26, '03 05:43:01PM

I cannot save the invisible script.I copied and pasted everything from this hint into the script editor but when I try to save it it says:

Expected "then", etc. but found unknown token.

It highlights the question mark in this line towards the top:

if ii ? 1 then

How can I fix this?


Mark

---
Forgive the self promotion...

Add the AboveCalifornia Sherlock channel!
sherlock://www.AboveCalifornia.com/sherlock/SherlockChannel.xml?action=add



[ Reply to This | # ]
10.3: A set of AppleScripts to toggle item visiblity
Authored by: kerbaugh on Dec 01, '03 07:51:14AM

Forgive the tardiness of the response but I only just encountered this. I would have to conjecture, based on the logic, that the "question mark" in line 23 of the "Make Invisible" should be a "greater than" symbol.



[ Reply to This | # ]
10.3: A set of AppleScripts to toggle item visiblity
Authored by: Gnarlodious on Dec 21, '03 01:13:15AM
The line

if ii ? 1 then 

contains an error. Looks like the "?" character should be a comparison operator. If so, it didn't translate well to HTML

 < , > , = or != (not equal) 

are some likely candidates.

---
If you're going to sin, it might as well be original

[ Reply to This | # ]

I use OnMyCommand
Authored by: jecwobble on Nov 27, '03 01:09:56PM
I do something like this using OnMyCommand with this context menu setting:

		<dict>
			<key>ACTIVATION_MODE</key>
			<string>act_file_or_folder_not_finder_window</string>
			<key>COMMAND</key>
			<array>
				<string>/Developer/Tools/SetFile -a </string>
				<string>__INPUT_TEXT__</string>
				<string> </string>
				<string>__OBJ_PATH__</string>
			</array>
			<key>INPUT_DIALOG</key>
			<dict>
				<key>CANCEL_BUTTON_NAME</key>
				<string>Cancel</string>
				<key>DEFAULT</key>
				<string>Invisible</string>
				<key>INPUT_MENU</key>
				<array>
					<dict>
						<key>NAME</key>
						<string>Visible</string>
						<key>VALUE</key>
						<string>v</string>
					</dict>
					<dict>
						<key>NAME</key>
						<string>Invisible</string>
						<key>VALUE</key>
						<string>V</string>
					</dict>
				</array>
				<key>INPUT_TYPE</key>
				<string>input_popup_menu</string>
				<key>MESSAGE</key>
				<string>Select a visibility option.</string>
				<key>OK_BUTTON_NAME</key>
				<string>OK</string>
			</dict>


[ Reply to This | # ]
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 | # ]
10.3: A set of AppleScripts to toggle item visiblity
Authored by: rlicata on Apr 13, '04 06:35:21PM

FYI - I installed Developer Tools and used the Make Visible script (after I saved it as an application) and it works in Jaguar 10.2.8! Panther and Jaguar supported!

If anyone has ever had an Illustrator 10 file that saved as an EPS but said "could not save preview, but everthing else saved correctly", and the file disappeared, it actually became invisible. Running the Make Visible script on the file made it visible and allowed me to ZIP it with my project and post to meet my deadline!

15 minutes from install of DevTools to visible file - this is a ROCKIN script! Thx.



[ Reply to This | # ]