Hi,
I am trying to write a script that figures out if files that start with a dot are hidden. If they are, it will make them visible, and vice versa.
But my script only makes files visible, and can’t make them invisible again.
Here’s my script:
set sf to do shell script "defaults read com.apple.finder AppleShowAllFiles"
if sf = 1 then
do shell script "defaults write com.apple.finder AppleShowAllFiles -bool FALSE"
else
do shell script "defaults write com.apple.finder AppleShowAllFiles -bool TRUE"
end if
do shell script "killall Finder"
I tried to run the shell scripts separately and they all worked.
Additionally, I would appreciate very much if windows don’t need to be closed. Or can I get the paths of Finder windows and have them open again when I relaunch the Finder?
Thanks in advance
Sorry, I figured out what’s wrong.
The result returned by the shell is not a number, it’s a string. So I need to put the number one in quotes.
Here’s it:
set sf to do shell script "defaults read com.apple.finder AppleShowAllFiles"
if sf = "1" then
do shell script "defaults write com.apple.finder AppleShowAllFiles -bool FALSE"
else
do shell script "defaults write com.apple.finder AppleShowAllFiles -bool TRUE"
end if
do shell script "killall Finder"
This worked. But I didn’t figure out how to see the changes without closing all windows.
try
set state to ((do shell script "/usr/bin/defaults read com.apple.Finder AppleShowAllFiles") as integer) as boolean
on error
set state to false
end try
do shell script "/usr/bin/defaults write com.apple.Finder AppleShowAllFiles -bool " & ((not state) as text) & " ;killall Finder"