Applescript/Automator batch run "chflags -R nohidden" on folders.

I have a problem with some mac files become hidden on a windows file server.

Is the a way to make a AppleScript or Automator script so one can drop a folder onto to execute batch "chflags -R nohidden" terminal command?


Posted on Mar 17, 2023 7:22 AM

Reply
Question marked as Top-ranking reply

Posted on Mar 17, 2023 9:01 AM

You can use this Automator Application workflow where you drag and drop a folder containing chflags hidden files onto it, and they will be set to nohidden. You may need to visit System Preferences / Settings > Security & Privacy and set this application to full disk access. If not, it may pop a dialog asking for access to your Desktop, etc.


Tested on Ventura 13.2.1


Code:


#!/bin/zsh

: <<"COMMENT"
Drag and drop a folder that may contain chflags hidden files in it
onto this Automator application and have those hidden files made nohidden.
This is a recursive (**) case-insensitive script
COMMENT

STARTDIR="${@:a:s/\~\//}"

setopt nocaseglob

# return regular (.N) files sorted ascending by name (on)
for f in "${STARTDIR}"/**/*(.Non);
do
    [[ $(stat -f '%Sf' "${f}") == "hidden" ]] || continue
    /usr/bin/chflags nohidden "${f}"
done
exit




3 replies
Question marked as Top-ranking reply

Mar 17, 2023 9:01 AM in response to arve224

You can use this Automator Application workflow where you drag and drop a folder containing chflags hidden files onto it, and they will be set to nohidden. You may need to visit System Preferences / Settings > Security & Privacy and set this application to full disk access. If not, it may pop a dialog asking for access to your Desktop, etc.


Tested on Ventura 13.2.1


Code:


#!/bin/zsh

: <<"COMMENT"
Drag and drop a folder that may contain chflags hidden files in it
onto this Automator application and have those hidden files made nohidden.
This is a recursive (**) case-insensitive script
COMMENT

STARTDIR="${@:a:s/\~\//}"

setopt nocaseglob

# return regular (.N) files sorted ascending by name (on)
for f in "${STARTDIR}"/**/*(.Non);
do
    [[ $(stat -f '%Sf' "${f}") == "hidden" ]] || continue
    /usr/bin/chflags nohidden "${f}"
done
exit




This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Applescript/Automator batch run "chflags -R nohidden" on folders.

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.