hiding a folder

Dear Applescripters,

Is it possible to hide/unhide a foider with applescript?

Thank you in advance for any answers,
Jan B.

Model: Powerbook 2Gz dual core
AppleScript: 1.10.7
Browser: Safari 531.21.10
Operating System: Mac OS X (10.4)

Here is a Ruby script that will do what you want. It will toggle hidden status on a file or folder.
Don’t worry if this is a bit scary, someone will probably post an AppleScript example shortly. :slight_smile:

Save it with a .rb extension and call it from AppleScript like this.

The paths need to be POSIX paths.

do shell script "ruby " & quoted form of rubyFilePath & quoted form of itemToHideRevealPath

Ruby Script.

System Events can set the visible flag for a file or folder:

set f to missing value
	set f to choose file with prompt "Choose a file to hide/unhide. Click Cancel to choose a folder." with invisibles
end try
if f is missing value then ¬
	set f to choose folder with prompt "Choose a folder to hide/unhide." with invisibles
set p to POSIX path of f

tell application "System Events" to set v to visible of disk item p

set {s, d} to {"not hidden", "Hide"}
if not v then set {s, d} to {"hidden", "Unhide"}
display dialog p & " is currently " & s buttons {"Cancel"} & d default button d

tell application "System Events" to set visible of disk item p to not v

tell application "Finder" to update f
-- On 10.4, update is not immediately effective. For open Finder windows, must navigate away and back before change will be effective. For desktop, have to quit and restart Finder, since you can not navigate away from the desktop.
-- generally, too disruptive to really consider
tell application "Finder" to quit
tell application "System Events" to repeat until not (exists application process "Finder")
	delay 0.1
end repeat
tell application "Finder" to launch

Model: iBook G4 933
AppleScript: 1.10.7
Browser: Safari 4.0.4 (4531.21.10, r52242)
Operating System: Mac OS X (10.4)

Both Graig and Chrys, thank you for the assistance.

Greetings from sunny Bonaire N.A.

Nice chrys. I updated my script to use the less disruptive “update” command. Much better!