Show hidden files self service

makander
Contributor

I was lurking in the "show of your self service" thread the other day and saw that user @rlandgraf had a policy that could show and hide hidden files. I thought this was genius and figured I'd create a similar policy by writing two scripts:

#!/bin/sh
defaults write com.apple.finder AppleShowAllFiles true
killall Finder

#!/bin/sh
defaults write com.apple.finder AppleShowAllFiles false
killall Finder

I dropped these into a /Library/Application Support/JAMF/Scripts and tried to call them with a command in self service. For some reason I can't get this to work and I've been at it for ... to long now, it's starting to get embarrassing. Maybe there's someone here that can figure out what I'm doing wrong. What it does is that it restarts the Finder but the files remain hidden but if I run the scripts through terminal they work just fine.

I've tried changing owner and permissions and I thought I got it to work by using #!/bin/bash instead of sh but that didn't work either.

6 REPLIES 6

m_entholzner
Contributor III
Contributor III

The command you wrote sets the key for "root" 'cause all scripts executed via Self Service are run as root.
Use this one to get your current logged in user:

USERNAME=$(ls -l /dev/console | cut -d " " -f 4)
USERHOME=$(dscl . read /Users/${USERNAME} NFSHomeDirectory | cut -d ' ' -f2)

then
defaults write ${USERHOME}/Library/Preferences/com.apple.finder AppleShowAllFiles -bool true

makander
Contributor

I am doing this right now @entholzner][/url? Because I'm getting: "Result of command /L/AS/JAMF/Scripts/showhiddenfiles.sh: line 6: syntax error near unexpected token `then' /L/AS/JAMF/Scripts/showhiddenfiles.sh: line 6: `then'

#!/bin/bash

USERNAME=$(ls -l /dev/console | cut -d " " -f 4)
USERHOME=$(dscl . read /Users/${USERNAME} NFSHomeDirectory | cut -d ' ' -f2)

then
defaults write ${USERHOME}/Library/Preferences/com.apple.finder AppleShowAllFiles -bool true

killall Finder

m_entholzner
Contributor III
Contributor III

okay, step by step :)

I posted only the parts to change in the script. here's the full one:

#!/bin/bash

USERNAME=$(ls -l /dev/console | cut -d " " -f 4)
USERHOME=$(dscl . read /Users/${USERNAME} NFSHomeDirectory | cut -d ' ' -f2)

defaults write ${USERHOME}/Library/Preferences/com.apple.finder AppleShowAllFiles -bool true
killall Finder
exit 0

Just upload the script in the JSS and call it via policy. You don't have to call it locally.

makander
Contributor

Thanks! :)

Hmm, it's still just restarting the Finder. Weird. :S

I'm calling it via a policy and it's set to after.

I've tried editing the script to but nope, it doesn't want to do what I want it to.

Matt
Valued Contributor

You could also bypass Self Service and use a contextual item.

makander
Contributor

Hi Matt, I'm not sure what you mean.. could you explain?