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

An AppleScript to quickly show or hide hidden files Desktop
I enjoy using GUI Finder, but find I need to access the hidden files sometimes. So I created a quick AppleScript (using its ability to call shell scripts) to efficiently switch between hidden files off and on. Here it is:
tell application "Finder" to quit
display dialog "Show Hidden Files..." buttons {"ON", "OFF"} 
  default button 3
copy the result as list to {buttonpressed}

try
  if the buttonpressed is "OFF" then do shell script 
    "defaults write com.apple.finder AppleShowAllFiles OFF"
  if the buttonpressed is "ON" then do shell script 
    "defaults write com.apple.finder AppleShowAllFiles ON"
end try

tell application "Finder" to launch
This is my first AppleScript so I am very open to any improvements to it. Perhaps this will be of some assisstance to people like myself. I found it handy to place this script in the Script Menu, and hotkeyed this script also.

[robg adds: I tested this script and it works as expected.]


Panther proven!
    •    
  • Currently 1.20 / 5
  You rated: 2 / 5 (5 votes cast)
 
[152,754 views]  

An AppleScript to quickly show or hide hidden files | 56 comments | Create New Account
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: luhmann on Apr 10, '03 10:46:17AM

This works great! I've been using either Cocktail or TinkerTool to do this, but this script is so much faster. Thanks!



[ Reply to This | # ]
An AppleScript to quickly show or hide hidden files
Authored by: kevyang on Apr 10, '03 10:58:44AM

Neat! Thanks!



[ Reply to This | # ]
An AppleScript to quickly show or hide hidden files
Authored by: zweigand on Apr 10, '03 11:21:05AM

the script did work fine for me ...but i'm posting a revison that allows you to Cancel the script (so if you accidentally click the wrong script ...your finder doesn't restart)

display dialog "Set the visibility of hidden files...
" buttons {"Cancel", "Visible", "Invisible"} default button 1
tell application "Finder" to quit
set buttonpressed to the return of the result
if the buttonpressed is "Invisible" then
try
do shell script "defaults write com.apple.finder AppleShowAllFiles OFF"
end try
else if the buttonpressed is "Visible" then
try
do shell script "defaults write com.apple.finder AppleShowAllFiles ON"
end try
end if
tell application "Finder" to launch



[ Reply to This | # ]
An AppleScript to quickly show or hide hidden files
Authored by: arulprakash on May 22, '06 06:07:14AM

hi am a new MAC user can u pls let me know how do i go abt implementing the apple script u've typed in here



[ Reply to This | # ]
An AppleScript to quickly show or hide hidden files
Authored by: zweigand on Apr 10, '03 12:03:12PM
please disregard my last post!! ...that script does not work! (feel rather stupid ;) ...here is a better one..that DOES work (for me anyway!) ...i had to throw a delay in because apparently the script was done before the finder fully quit... and this wouldn't allow the finder to restart!
display dialog "Set the visibility of hidden files..." buttons {"Cancel", "Visible", "Invisible"} default button 1
copy the result as list to {buttonpressed}
if the buttonpressed is "Invisible" then
      try
		tell application "Finder" to quit
		do shell script "defaults write com.apple.finder AppleShowAllFiles OFF"
		delay 1
		tell application "Finder" to activate
	end try
else if the buttonpressed is "Visible" then
	try
		tell application "Finder" to quit
		do shell script "defaults write com.apple.finder AppleShowAllFiles ON"
		delay 1
		tell application "Finder" to activate
	end try
end if


[ Reply to This | # ]
An AppleScript to quickly show or hide hidden files
Authored by: frogstomp on Apr 10, '03 02:13:49PM

This is strange for me. I can not seem to get this script to re-
launch the Finder after selecting 'invisible' or 'visable'.

The script seems to hang at 'delay 1'

It works for you, I am curious to understand why not for
myself?

Just as a note from my experience working out this script, the
reason I have `tell application "Finder" to quit ' at the
beginning of the script is, if I had that line anywhere else in my
script, I was unable to relaunch the finder. Also to note, that
whenever I was unable to Script Launch the finder, the defaults
attribute would not change... Strange hey.

Thanks for the reply and suggestions, I am learning a lot by
other peoples code.

cheers!



[ Reply to This | # ]
It works for me now...
Authored by: frogstomp on Apr 10, '03 02:32:29PM

Just wanted to note that your script does work for me now.

For whatever reason Any of the 'Working' scripts which quit the
finder and relaunch them tend to be a little buggy.

Sometimes these scripts when run from the ScriptEditor will
hang at the "tell application "Finder" to quit" line.

Other times the Finder will not relaunch.

Once the script is in a working state though, it seems to work
99% of the time...

Just a strange observation with my finder,

Thank you again, I do appreciate the help learning.



[ Reply to This | # ]
It works for me now...
Authored by: zweigand on Apr 10, '03 03:58:51PM

glad it works now... i had never used a script to quit the finder like that... i had to tweak it so that (as you said) the finder would relaunch ....it was a learning experince for me as well ;)



[ Reply to This | # ]
An AppleScript to quickly show or hide hidden files
Authored by: OmniDragon on Apr 04, '10 12:09:12PM

"please disregard my last post!! ...that script does not work! (feel rather stupid ;)"

Shouldn't feel too bad. The original poster's script didn't work either. He called out a button variable that he didn't define resulting in:

"Specified button does not exist."

Had to change "default button 3" to "default button 2" because there IS no button 3



[ Reply to This | # ]
An AppleScript to quickly show or hide hidden files
Authored by: leenoble_uk on Apr 10, '03 12:10:00PM

Throw a copy on the top level of your iPod ;-)

You know what it's for



[ Reply to This | # ]
An AppleScript to quickly show or hide hidden files
Authored by: charles2003 on May 15, '03 12:49:44AM
Use this script once to show hidden iPod Folders, then make aliases to these folders. The next time you need to add iPod files to a playlist in iTunes, click the aliases an drag the files to your iTunes playlist. This is one the few ways you can mix MP3 files on your iPod and MP3 files on your Hard Disk into the same playlist. (Another idea is just drag all your iPod files into one playlist called "iPod Files." Then you can easily make playlists, since all the files will now be in your main iTunes libary.)
  • F00 alias
  • F11 alias
  • F10 alias
  • F09 alias
  • F08 alias
  • F07 alias
  • F06 alias
  • F04 alias
  • F03 alias
  • F18 alias
  • F15 alias
  • F17 alias
  • F13 alias
  • F12 alias
  • F14 alias
  • F05 alias
  • F19 alias
  • F16 alias
  • F02 alias
  • F01 alias This is one the only ways you can mix MP3 files on your iPod and MP3 files on your Hard Disk into the same playlist. Too bad Apple can't make their iPod as friendly as some of their competitor's MP3 players!

    [ Reply to This | # ]
  • Toggle show or hide hidden files
    Authored by: robmorton on Apr 10, '03 12:11:56PM

    Same thing but without all the mouse clicks (Watch the line wraps obviously)...

    tell application "Finder" to quit
    set OnOff to do shell script "defaults read com.apple.finder AppleShowAllFiles"
    if OnOff = "NO" or OnOff = "OFF" then
    set OnOff to "ON"
    else
    set OnOff to "OFF"
    end if
    do shell script "defaults write com.apple.finder AppleShowAllFiles " & OnOff
    tell application "Finder" to launch



    [ Reply to This | # ]
    Toggle show or hide hidden files
    Authored by: Loren on Apr 10, '03 12:22:25PM

    For some reason, for me, this one doesn't relaunch the finder when done.



    [ Reply to This | # ]
    Toggle show or hide hidden files
    Authored by: frogstomp on Apr 10, '03 02:01:25PM

    I really like the idea behind this particular Script; however, for
    some reason the Finder will not re-launch and when re-running
    the script to toggle back to 'Hide' hidden files I receive an
    Execution Error ... pertaining to Quit.

    These are the same problems I initially had when writing my
    script as I originally wanted it to 'Toggle' as you suggest.

    Great idea, I wonder why it does not work?

    Thanks.



    [ Reply to This | # ]
    Toggle show or hide hidden files - FIXED
    Authored by: rselph on Apr 10, '03 02:09:13PM
    Try this:
    tell application "Finder" to quit
    set OnOff to do shell script "defaults read com.apple.finder AppleShowAllFiles"
    if inOff= "NO" or inOff= "OFF" then
    	set OnOffCommand to "defaults write com.apple.finder AppleShowAllFiles ON"
    else
    	set OnOffCommand to "defaults write com.apple.finder AppleShowAllFiles OFF"
    end if
    do shell script OnOffCommand
    delay 1
    tell application "Finder" to launch
    


    [ Reply to This | # ]
    Wierd....
    Authored by: rselph on Apr 10, '03 02:13:39PM

    Strange. I pasted in the above code, but something on the web site decided to change it just a little bit.

    The variable in the "if" clause should be "OnOff", not "inOff" as shown above.



    [ Reply to This | # ]
    Wierd....
    Authored by: frogstomp on Apr 10, '03 02:26:32PM

    Yes it works now, nice!

    One question though. Now and again I revieve an error
    message the "the connection is invalid" I believe on the finder
    quit line.

    What's up with that?
    Is it a limitation with scripting the finder?

    Thanks, I like this script the most since it is originally what I
    wanted ... Strangely enough though, the reason I wrote mine
    was to try and avoid the error message I mentioned here. It
    does seem to occur with my script also though, and any script
    with "tell application "Finder" to quit" from time to time.

    odd...



    [ Reply to This | # ]
    Wierd....
    Authored by: rselph on Apr 10, '03 03:12:42PM

    I haven't seen that myself, and I'm not enough of an Apple Script expert to know anything about it. Sorry.



    [ Reply to This | # ]
    Beat me to the punch
    Authored by: jecwobble on Apr 11, '03 12:35:12AM
    I wasn't at my Mac when I read this hint, so I couldn't test anything until just now. I merged two of the concepts above and came up with something very similar to yor fix, but I included a "try" statement that may alleviate some of the "connection failed" errors.
    set OnOff to do shell script "defaults read com.apple.finder AppleShowAllFiles"
    if inOff= "NO" or inOff= "OFF" then
            set OnOffCommand to "defaults write com.apple.finder AppleShowAllFiles ON"
    else
            set OnOffCommand to "defaults write com.apple.finder AppleShowAllFiles OFF"
    end if
    try
            tell application "Finder" to quit
            do shell script OnOffCommand
            delay 1
            tell application "Finder" to launch
    end try
    


    [ Reply to This | # ]
    Beat me to the punch
    Authored by: Kool on Apr 11, '03 08:14:55AM
    This only works once the preference is once set. So it is needed to at least once type "defaults write com.apple.finder AppleShowAllFiles ON" in the Terminal (or set it with TinkerTool, or any other utility that does this...)

    [ Reply to This | # ]
    Another way
    Authored by: DanCleaver on May 13, '10 03:49:27PM

    Just a thought, but you can get around problems with quitting and launching the finder mid-script by setting the default the killing the finder:

    display dialog "Show Hidden Files..." buttons {"ON", "OFF"} default button 2
    copy the result as list to {buttonpressed}

    try
    if the buttonpressed is "OFF" then do shell script
    "defaults write com.apple.finder AppleShowAllFiles OFF"
    if the buttonpressed is "ON" then do shell script
    "defaults write com.apple.finder AppleShowAllFiles ON"
    end try
    do shell script "killall Finder"



    [ Reply to This | # ]
    !!! THIS IS THE MOST ELEGANT CODE !!!
    Authored by: theHub on Jun 11, '10 03:00:29PM
    DanCleaver (above) posted the simple (elegant) answer, but I also liked the idea of a "Cancel" button mentioned by one of the other posters. Following the general rule of Least Harmful by Default...
    
    display dialog " Show Hidden Files ?" buttons {"Yes", "No", "Cancel"} default button 3
    copy the result as list to {buttonpressed}
    
    try
    	if the buttonpressed is "Cancel" then quit
    	if the buttonpressed is "No" then do shell script 
    		"defaults write com.apple.finder AppleShowAllFiles OFF"
    	if the buttonpressed is "Yes" then do shell script 
    		"defaults write com.apple.finder AppleShowAllFiles ON"
    end try
    do shell script "killall Finder"
    
    Thanx DanCleaver.

    [ Reply to This | # ]
    !!! OF COURSE YOU COULD COMBINE !!!
    Authored by: theHub on Jun 11, '10 05:41:08PM
    the second if statement of the try thus...
    	if the buttonpressed is "No" then
    		do shell script 
    			"defaults write com.apple.finder AppleShowAllFiles OFF"
    	else
    		do shell script 
    			"defaults write com.apple.finder AppleShowAllFiles ON"
    	end if
    


    [ Reply to This | # ]
    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 | # ]
    An AppleScript to quickly show or hide hidden files
    Authored by: echo on Apr 10, '03 03:29:39PM

    Thank you so much!
    I've wanted this for a long time, as I use TinkerTool for this constantly.



    [ Reply to This | # ]
    An AppleScript to quickly show or hide hidden files
    Authored by: ChaChi on Apr 10, '03 06:50:34PM

    Just thought I'd add a script that I wrote to do this a while back. I still use it all the time.

    You'll want to save this script as a "Stay Open" Application (if you need help doing this, please feel free to ask for help). After you launch it, it will stay open until you tell it to quit. You quit it by clicking the button that's named (of all things) "Quit". Clicking on it's dock icon, after it has run, will "reopen" (or re-run) the script. Hopefully it's fairly straight forward once you try it out for the first time. Hope someone gets as much use out of this as I have. Here it is:

    --Start Script
    on run
    try
    set CurrentSetting to (do shell script "defaults read com.apple.finder AppleShowAllFiles")
    on error
    set CurrentSetting to "0"
    end try
    if CurrentSetting is "0" then
    set theText to "Show invisibles?"
    set thelist to {"Show & Idle", "Show & Quit", "Stay Idle"}
    else
    set theText to "Hide invisibles?"
    set thelist to {"Hide & Idle", "Hide & Quit", "Stay Idle"}
    end if
    activate
    set thechoice to (choose from list thelist with prompt theText default items (item 1 of thelist) cancel button name "Quit")
    if thechoice is not false then
    if thechoice is not in (item 3 of thelist) then
    if "Show" is in (thechoice as string) then
    set thesetting to "1"
    else if "Hide" is in (thechoice as string) then
    set thesetting to "0"
    end if
    do shell script "defaults write com.apple.finder AppleShowAllFiles " & thesetting
    tell application "System Events"
    if "Finder" is in name of processes then tell application "Finder" to quit
    delay 1
    end tell
    launch application "Finder"
    end if
    if "Quit" is in (thechoice as string) then
    quit
    return
    end if
    hideme()
    else
    quit
    end if
    end run

    on reopen
    run
    end reopen

    on quit
    continue quit
    end quit

    on hideme()
    tell application "System Events" to set visible of processes whose frontmost is true to false
    end hideme
    --End Script



    [ Reply to This | # ]
    An AppleScript to quickly show or hide hidden files
    Authored by: duboisj on Apr 27, '03 12:40:04PM
    I want the finder to show files which have a '.' at the beginning of their names, but not to show files which are listed in the .hidden file of each folder. It seems that setting AppleShowAllFiles shows *all* files, without looking at the .hidden file. Unsetting AppleShowAllFiles makes it so that '.' files are hidden.

    Is there any way to get more selective hiding? Thanks!

    [ Reply to This | # ]

    An AppleScript to quickly show or hide hidden files
    Authored by: brettpat on May 19, '03 07:03:19AM

    I'm looking for a script to show only '.htaccess' files, (and leave all others hidden) so they show in the Finder and within GoLive.

    Is there a way to do this, perhaps as a script at startup?



    [ Reply to This | # ]
    An AppleScript to quickly show or hide hidden files
    Authored by: toothfish on Jul 27, '03 09:23:31PM
    I'd be interested if anyone comes up with a solution to this as well-- or possibly the inverse. the only files i'm not interested in seeing would be .DS_Store, etc. any dot-files i download from my webserver i'd like to be visible, and they're not always .htaccess. sort of the same result, though.

    [ Reply to This | # ]
    Showing . files
    Authored by: jglenn on Aug 26, '03 05:23:37PM

    this is close to what you want:

    In the Finder, type command-F, then add criteria, and choose visibility. Set visibility to Off, and then do a search on words whose filename starts with "."

    You'll get all the hidden files that begin with . , but you get them even if they are listed in the "hidden" database. Hope that's not a problem.



    [ Reply to This | # ]
    An AppleScript to quickly show or hide hidden files
    Authored by: GaelicWizard on Nov 21, '03 05:33:47PM
    Since everyone else has been posting their versions, iThought I'd post mine. :-)

    Very simple script, sort-of canibalized from previous posts. :-)

    Basically it checks the current state, then asks what you want the state to be. If you click the state that it already is, then nothing happens, otherwise the finder quits and then restarts. :-)

    Here it is:
    tell application "Finder"
    	activate
    	set previous to "NO"
    	set previous to do shell script "defaults read com.apple.finder AppleShowAllFiles"
    	display dialog "Show Hidden Files... " & previous buttons {"TURN ON", "TURN OFF"} default button 2
    	copy the result as list to {buttonpressed}
    	
    	if previous is "ON" and the buttonpressed is "TURN OFF" then
    		do shell script "defaults write com.apple.finder AppleShowAllFiles OFF"
    		quit
    	end if
    	if previous is "OFF" and the buttonpressed is "TURN ON" then
    		do shell script "defaults write com.apple.finder AppleShowAllFiles ON"
    		quit
    	end if
    end tell
    
    delay 1
    tell application "Finder" to launch
    

    ---
    Pell

    [ Reply to This | # ]

    An AppleScript to quickly show or hide hidden files
    Authored by: gaston@mac.com on Dec 05, '03 04:38:20AM

    I keep getting an error:

    "2003-12-05 10:37:21.795 defaults[475]
    The domain/default pair of (com.apple.finder, AppleShowAllFiles) does not exist"

    What's going wrong?



    [ Reply to This | # ]
    An AppleScript to quickly show or hide hidden files
    Authored by: Zerk78 on Jun 23, '04 12:07:09PM

    I felt free to translate this script to a Dutch version... With the upcomming kick-off of a Dutch version of this site, I'll be pleased to translate more to Dutch...

    Translating the question and button-text didn't effect the script.. Just be sur e to ONLY translate the text... not the file-locations.... I guess it works in whatever language....



    [ Reply to This | # ]
    An AppleScript to quickly show or hide hidden files
    Authored by: hofman on Jul 25, '04 07:25:00AM
    And then here is my version. The main difference is in the RelaunchFinder function which, oh surprise, relaunches the Finder. It tries several times to launch and therefore adjusts the delay to whatever is needed, which typically is less than 1 second.
    
    tell application "Finder"
    	activate
    	set OnOff to "Off"
    	set OnOff to do shell script "defaults read com.apple.finder AppleShowAllFiles"
    	if OnOff is "OFF" or OnOff is "NO" or OnOff is "0" then
    		set OnOff to "ON"
    		set ShowHide to "show"
    	else
    		set OnOff to "OFF"
    		set ShowHide to "hide"
    	end if
    	display dialog "Are you sure you want to " & ShowHide & " hidden files?" buttons {"Cancel", "OK"} default button 2
    	set buttonPressed to the result
    	if buttonPressed is "OK" then
    		do shell script "defaults write com.apple.finder AppleShowAllFiles " & OnOff
    		my RelaunchFinder()
    	end if
    end tell
    
    on RelaunchFinder()
    	try
    		tell application "Finder" to quit
    	on error
    		error "Unable to quit Finder. You may want to force quitting it (cmd-option-esc) to have the change take effect."
    	end try
    	set finderIsActive to false
    	set errorCount to 0
    	repeat until finderIsActive
    		try
    			tell application "Finder" to activate
    			set finderIsActive to true
    		on error
    			set errorCount to errorCount + 1
    			if (errorCount > 20) then
    				error "Unable to restart Finder. Please click the Finder icon in the dock to restart it."
    			end if
    			delay 0.2
    		end try
    	end repeat
    end RelaunchFinder
    


    [ Reply to This | # ]
    An AppleScript to quickly show or hide hidden files
    Authored by: granlord on Nov 19, '04 04:47:42PM

    Tried this script and got the folowing error msg any ideas?

    The domain/default pair of (com.apple.finder, AppleShowAllFiles) does not exist

    Regards H



    [ Reply to This | # ]
    After reading ALL OF THE THREADS...
    Authored by: BrunoUsesBBEdit on Feb 01, '05 05:54:58PM
    I've combined everything in to one top level post, so other don't have to dig as deep as I did.

    The best implementation of this concept is a single AppleScript that toggles the visibility of hidden unix files without user input. (Once ran by the user.)

    I call this Script "Toggle invisible Unix files" and I have is sitting in my Finder Window Toolbar.

    I tested the "Delay 1" which is necessary to get the changes done before Finder is told to launch. It seams that you can drop it to "Delay 0.25" which still works, but causes it to run much faster. (about 4x)

    
    set OnOff to do shell script "defaults read com.apple.finder AppleShowAllFiles"
    if inOff= "NO" or inOff= "OFF" then
    	set OnOffCommand to "defaults write com.apple.finder AppleShowAllFiles ON"
    else
    	set OnOffCommand to "defaults write com.apple.finder AppleShowAllFiles OFF"
    end if
    try
    	tell application "Finder" to quit
    	do shell script OnOffCommand
    	delay 0.25
    	tell application "Finder" to launch
    end try
    

    ---

    --==>==--

    [ Reply to This | # ]

    Whoops, OnOff becoming inOff!
    Authored by: ageless on Feb 10, '05 05:09:12AM

    The variable name changes from OnOff on line 1 to inOff on line 2, because of the macoshints software, e.g. geeklog -- or so it would appear! For some reason it leaves the first line alone, but on the second line it changes OnOff to inOff -- try it for yourself, just preview your post but don't submit it. -- it works 'unprotected' and also when wrapped in \[code\]\[/code\] tags -- heh, just found another way to break the software, try previewing \[code\]\[/code\] with less backslashes to protect the brackets -- when I did it looked like this:

    Fatal error: Allowed memory size of 16777216 bytes exhausted (tried to allocate 7447497 bytes) in /home/virtual/site40/fst/var/www/html/lib-common.php on line 2746

    Here is a corrected version of the above, using stateOfShowAllFiles instead of OnOff, thus making it macoshints compatible! What an upgrade! Oh, and I made a number of other changes as well, enjoy!

    To be fair to geeklog this might be an older version of the software and of course it may be a known bug that is being/will be fixed -- anyone want to to track that down?

    The code below works perfectly on my G4 running 10.3.7.

    (*
    Toggle AppleShowAllFiles
    http://www.macosxhints.com/article.php?story=20030409015020645
    *)
    set shellScriptToDo to ""
    set firstRun to ""
    try
    	set stateOfShowAllFiles to do shell script "defaults read com.apple.finder AppleShowAllFiles"
    on error
    	display dialog "Looks like the variable 'AppleShowAllFiles' doesn't have a value yet, so you are probably running this AppleScript for the first time.*
    
    Are you sure you want to set AppleShowAllFiles to ON?
    
    _________________________________________________
    
    * If this is not the first run, consider this message an error!" buttons {"Cancel", "OK"} default button 2
    	set buttonPressed to the result
    	if buttonPressed is "Cancel" then
    		set firstRun to "CANCEL"
    	else
    		set shellScriptToDo to "defaults write com.apple.finder AppleShowAllFiles ON"
    	end if
    end try
    if firstRun is not equal to "CANCEL" then
    	if shellScriptToDo = "" then
    		if stateOfShowAllFiles = "ON" then
    			set shellScriptToDo to "defaults write com.apple.finder AppleShowAllFiles OFF"
    		else
    			set shellScriptToDo to "defaults write com.apple.finder AppleShowAllFiles ON"
    		end if
    	end if
    	try
    		tell application "Finder" to quit
    	on error
    		error "Unable to quit Finder. You may want to force quitting it (cmd-option-esc) to have the change take effect."
    	end try
    	try
    		do shell script shellScriptToDo
    	on error
    		error "Shell script '" & shellScriptToDo & "' failed!"
    	end try
    	delay 0.25
    	try
    		tell application "Finder" to activate
    	on error
    		delay 0.1
    		tell application "Finder" to activate
    	end try
    end if


    [ Reply to This | # ]
    An AppleScript to quickly show or hide hidden files
    Authored by: Zo-1 on Feb 10, '05 06:01:37AM

    Not to spoil your fun, boys, but Invisibles, a small app, free from http://www.mac4ever.de works just great, and the older script Sneak A Peak seems to as well, also free. http://www.nonamescriptware.com



    [ Reply to This | # ]
    An AppleScript to quickly show or hide hidden files
    Authored by: mlang on Jun 12, '05 04:28:30PM
    well, this thread is mighty old, but if anybody happens along, i wanted to throw my hat into the ring. much shorter and simpler than some of the offerings here, but it seems to work quite smoothly for me.
    
    property workingfilename : "~/Library/Preferences/com.apple.finder.plist"
    tell application "Finder"
    	quit
    	tell application "System Events"
    		get value of property list item "AppleShowAllFiles" of contents of property list file workingfilename
    		if result = "Yes" then
    			set value of property list item "AppleShowAllFiles" of contents of property list file workingfilename to "No"
    		else
    			set value of property list item "AppleShowAllFiles" of contents of property list file workingfilename to "Yes"
    		end if
    		delay 1
    		tell application "Finder"
    			launch
    		end tell
    	end tell
    end tell
    


    [ Reply to This | # ]
    An AppleScript to quickly show or hide hidden files
    Authored by: calvarez on Jun 18, '05 03:20:25PM

    These don't seem to work on Tiger. The scripts run and blink, but do nothing. Any ideas on what needs to be changed to make them Tiger-compatible?



    [ Reply to This | # ]
    An AppleScript to quickly show or hide hidden files
    Authored by: calvarez on Jun 19, '05 01:07:36AM

    Well, I answered my own question...

    For Tiger, the variables need to be "TRUE" and "FALSE". Using that in any of the above scripts works.



    [ Reply to This | # ]
    Browse with SFTP app....
    Authored by: SuperCrisp on May 13, '06 06:07:03PM

    My solution may not work for all, but I use Fetch to browse localhost via SFTP and allowing the display files preceded by a period. This is more convenient for me than a finder restart. You can also use Fugu, Transmit, or whatever.



    [ Reply to This | # ]
    An AppleScript to quickly show or hide hidden files
    Authored by: swokm on Sep 06, '06 03:47:47PM
    My preferred version below. Don't like toggling, and this way I can't forget to change it back before logging out. Fast. Simple. I like simple.
    
    my BounceFinder("ON")
    display dialog ("Currently showing invisible files.") buttons {"Quit"} default button {"Quit"}
    my BounceFinder("OFF")
    
    on BounceFinder(FileVis)
    	tell application "Finder" to quit
    	do shell script "defaults write com.apple.finder AppleShowAllFiles " & FileVis
    	delay 0.2
    	tell application "Finder" to activate
    end BounceFinder
    
    (OS X 10.3.9)

    [ Reply to This | # ]
    An AppleScript to quickly show or hide hidden files
    Authored by: xhints_ on Feb 15, '08 05:24:21PM
    A bit late, perhaps, but this page still ranks quite highly on Google.
    
    
    
    display dialog "This operation will kill the Finder. Do not use if you are copying, moving, deleting, backing up etc." -- You can delete this line if you find it annoying, but it does make you think twice.
    
    if (do shell script "defaults read com.apple.finder AppleShowAllFiles") as boolean = false then
    	do shell script "defaults write com.apple.finder AppleShowAllFiles -bool true; killall Finder"
    else
    	do shell script "defaults write com.apple.finder AppleShowAllFiles -bool false; killall Finder"
    end if


    [ Reply to This | # ]
    An AppleScript to quickly show or hide hidden files
    Authored by: johnsawyercjs on Feb 16, '08 01:36:40AM

    It's better to quit from the Finder than to kill its process, so Finder windows that were open before the quit, will reopen when Finder is relaunched.



    [ Reply to This | # ]
    An AppleScript to quickly show or hide hidden files
    Authored by: marsofearth on Apr 20, '09 01:03:32PM
    Updated the script so it works with Leopard 10.5.6 (Tested)

    code originally from BrunoUsesBBEdit

    delay 0.3
    -- Had to add this delay at the start
    -- For some reason script would hang when OnOFF = 0
    -- Adding the Delay at the beginning fixed the issue
    set OnOff to do shell script "defaults read com.apple.finder AppleShowAllFiles"
    if OnOff = "1" then
    set OnOffCommand to "defaults write com.apple.finder AppleShowAllFiles 0"
    else
    set OnOffCommand to "defaults write com.apple.finder AppleShowAllFiles 1"
    end if
    try
    tell application "Finder" to quit>br> do shell script OnOffCommand
    delay 0.3
    tell application "Finder" to launch
    end try

    I compiled the script as an Application and set the GUI so it would not appear in the dock when activated.
    I have this little app sitting in my finder toolbar to quickly toggle file visablility as needed

    All files can be downloaded from here --->> http://stashbox.org/492996/ShowInvisibles.zip
    I hope this helps anyone!

    Mars

    [ Reply to This | # ]
    An AppleScript to quickly show or hide hidden files
    Authored by: johnsmth.smith15 on Jun 18, '09 02:26:53AM
    nice script man, found it very useful , keep up the good work JOhn from dedicated hosting

    [ Reply to This | # ]
    An AppleScript to quickly show or hide hidden files
    Authored by: tijlvuyk on Sep 03, '09 04:04:21AM

    This is an other simple way of doing it, this one just toggles the state

    try
    set state to do shell script "defaults read com.apple.finder AppleShowAllFiles" as string
    if state is "OFF" then
    do shell script "defaults write com.apple.finder AppleShowAllFiles ON"
    else
    do shell script "defaults write com.apple.finder AppleShowAllFiles OFF"
    end if
    end try
    tell application "Finder" to quit
    delay 1
    tell application "Finder" to launch



    [ Reply to This | # ]
    An AppleScript to quickly show or hide hidden files
    Authored by: Quatch on Oct 15, '09 11:18:42AM
    Anyone have a version of this that works in 10.6? I tried:
    
    delay 0.3
    -- Had to add this delay at the start
    -- For some reason script would hang when OnOFF = 0
    -- Adding the Delay at the beginning fixed the issue
    set OnOff to do shell script "defaults read com.apple.finder AppleShowAllFiles"
    if OnOff = "1" then
    set OnOffCommand to "defaults write com.apple.finder AppleShowAllFiles 0"
    else
    set OnOffCommand to "defaults write com.apple.finder AppleShowAllFiles 1"
    end if
    try
    tell application "Finder" to quit do shell script OnOffCommand
    delay 0.3
    tell application "Finder" to launch
    end try
    
    But, running produces an error:
     2009-10-15 14:17:39.892 defaults[1823:60f] 
    The domain/default pair of (com.apple.finder, AppleShowAllFiles) does not exist
    Thanks.

    [ Reply to This | # ]
    An AppleScript to quickly show or hide hidden files
    Authored by: Quatch on Oct 15, '09 11:20:27AM
    Oy. Answering my own question, by reading someone elses post.
    defaults write com.apple.finder AppleShowAllFiles -bool true
    that true/false instead of 1/0 is required in 10.6 Thank you and have a nice day :)

    [ Reply to This | # ]
    An AppleScript to quickly show or hide hidden files
    Authored by: Derby on Dec 27, '09 07:06:41AM

    Hi,
    if you want to do that with perl...so here it is a simple script:


    #!/usr/bin/perl -w

    use strict;
    use Getopt::Long;

    my ($var,$help,$fal,$tru);
    GetOptions(
    "false|f=s" => \$fal,
    "ture|t=s" => \$tru,
    "help|?" => \$help,
    );

    usage() if($help);
    if($fal){
    $fal="FALSE";
    print `defaults write com.apple.finder AppleShowAllFiles $fal`;
    print `killall Finder`;
    print "verbose FALSE\n";
    exit 1;
    }

    if($tru){
    $tru="TRUE";
    print `defaults write com.apple.finder AppleShowAllFiles $tru`;
    print `killall Finder`;
    print "verbose TRUE\n";
    exit 2;
    }

    #--- M A I N ----------------------------------------------------------------------------
    $fal='FASLE';
    $tru='TRUE';
    $var=`defaults read com.apple.finder AppleShowAllFiles`;
    chomp($var);
    print "var ist nun: $var\n";
    if($var =~ /^T/){
    print "var ist: TRUE\n";
    print `defaults write com.apple.finder AppleShowAllFiles $fal`;
    print `killall Finder`;
    }
    if($var =~ /^F/){
    print "var ist: FALSE\n";
    print `defaults write com.apple.finder AppleShowAllFiles $tru`;
    print `killall Finder`;
    }

    print "Can't change variable AppleShowAllFiles\n";
    exit 3;
    #========================================================

    sub usage{
    print "Syntax:\n";
    print "\t$0 [-f FASLE] [-t TRUE] [-?] [-v]\n";
    print "Description:\n";
    print "\tThis program changes the variable AppleShowAllFiles to show hidden files in Finder.\n";
    print "Flags:\n";
    print "\t\t-f FALSE Force the variable to FALSE\n";
    print "\t\t-t TRUE Force the variable to TRUE\n";
    print "\t\t-? Print this page\n";
    print "\t\t--help see -?\n";
    print "Examples:\n";
    print "1.\n";
    print "\t$0\n";
    print "2.\n";
    print "To force the variable AppleShowAllFiles to be TRUE:\n";
    print "\t$0 -t\n";
    exit;
    }



    [ Reply to This | # ]
    An AppleScript to quickly show or hide hidden files
    Authored by: ivanthehackrful on Aug 17, '10 05:09:14AM

    Thanks. I was trying to get files that begin with . and all sorts of crap like disks such as net and home off.

    one little improvement though. button 3 needs to be changed to button 1.



    [ Reply to This | # ]