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


Click here to return to the 'An AppleScript to quickly show or hide hidden files' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
An AppleScript to quickly show or hide hidden files
Authored by: klktrk on Apr 10, '03 03:13:58PM

Based on the excellent work of posters above, here's my version, which, to my mind improves the user experience in the following ways:
1. Finder does not quit unless user hits OK first. This way the script can be attached to a macro key stroke or some such thing without becoming annoying on a typo.
2. It does not ask the user to "think twice" about what state of visibility they want. It reads the current state, and assumes that the person wants to toggle the state. Therefore, the options are limited to Cancel and OK. No obtrusive need to rethink the action you already launched.

Here's my version:
set onOff to do shell script "defaults read com.apple.finder AppleShowAllFiles"
if onOff = "NO" or onOff = "OFF" then
set newState to "show"
set OnOffCommand to "defaults write com.apple.finder AppleShowAllFiles ON"
else
set newState to "hide"
set OnOffCommand to "defaults write com.apple.finder AppleShowAllFiles OFF"
end if

display dialog "Are you sure you want to " & newState & " hidden files? (This will restart the Finder)" buttons {"Cancel", "OK"} default button 2
copy the result as list to {buttonPressed}
if the buttonPressed is "OK" then
try
tell application "Finder" to quit
do shell script OnOffCommand
delay 1
tell application "Finder" to launch
end try
end if

BTW, this thread is interesting to me because it kind of exemplifies open source working right before your eyes, except we don't have CVS, just cut and paste. Excellent!

And thanks so much to the original poster, who triggered all this.

K



[ Reply to This | # ]
An AppleScript to quickly show or hide hidden files
Authored by: brising on Apr 10, '03 04:16:37PM

I found that I needed to add a bit to the line which read the current state of AppleShowAllFiles, as mine was set to 0:

if inOff= "NO" or inOff= "OFF" or inOff= "0" then

(boldface added) made things work OK.

Great idea!

-- Bill

P.S. in the preview for this note, the onOff in the code is showing up as inOff for some inexplicable reason...



[ Reply to This | # ]
An AppleScript to quickly show or hide hidden files
Authored by: jglenn on Aug 25, '03 10:08:24PM

yes, the original script didn't work for me, either, because the preference had never been set, ever, and so the "read" command failed with a dialog error message.

So, here's my improved version which doesn't display the error on newbies' systems:

set onOff to "NO"

try
set onOff to do shell script "defaults read com.apple.finder AppleShowAllFiles"
end try

if onOff = "NO" or onOff = "OFF" or onOff = "0" then
set newState to "show"
set OnOffCommand to "defaults write com.apple.finder AppleShowAllFiles ON"
else
set newState to "hide"
set OnOffCommand to "defaults write com.apple.finder AppleShowAllFiles OFF"
end if

display dialog "Are you sure you want to " & newState & " hidden files? (This will restart the Finder)" buttons {"Cancel", "OK"} default button 2
copy the result as list to {buttonPressed}
if the buttonPressed is "OK" then
try
tell application "Finder" to quit
do shell script OnOffCommand
delay 1
tell application "Finder" to launch
end try
end if



[ Reply to This | # ]
An AppleScript to quickly show or hide hidden files
Authored by: jiclark on Apr 11, '03 12:59:14PM

I can get this to work just fine from the Script Menu, but when I try and run it from iKey (formerly Youpi Key), I get a blank dialog that's un-dismissable (nice word, eh?). Any idea how to get rid of this short of logging out and logging back in???

NOT a huge deal, obviously, just a PITA...

Plus, I wonder why it doesn't work via iKey?..

Thanks for the effort all; I agree about the open-source atmosphere of the whole discussion, it's very exciting!

John-o

---



[ Reply to This | # ]
help a newbie with this script?
Authored by: rykey on Nov 08, '05 05:34:38AM

hi all,
first of all, thanks for the amazing curiosity and innovative solutions i've seen here--viva la open source! without people like you, we mac-dummies would be at the mercy of our factory settings.

i'm a newbie to stuff like scripts (to be honest, i'm far more interested in USING scripts than WRITING them), so forgive the ignorance... but how do i employ these scripts? i run OSX tiger, and i've gotten as far as pasting them into my script editor. do i save them as scripts? as script bundles? as applications? or what?

from here i gather that the "readable" scripts are put into folders where the system looks for its "cues" for a given application. so where would i want to put the hide/show hidden files script? and how will i know it's running (i'm guessing the appropriate dialog box will pop up when it's time to set the script on or off)?

thanks in advance for the patience and help.



[ Reply to This | # ]