Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

How to batch hide extensions using Automator or Finder Service?

I would like to generate a script in Automator that will hide all the file extensions in a folder. I have searched the various fora but no joy. Essentially I would like to create a Service or a Script that will hide the extensions in Finder for all the files in a selected folder. Ideally it would be recursive and drill down al the files/folders in the selected folder.

any assistance would be welcomed and appreciated

thanks

MacBook

Posted on Sep 23, 2019 3:56 PM

Reply
Question marked as Top-ranking reply

Posted on Sep 23, 2019 4:29 PM

If you are using a Bash script within an Automator Run Shell Script, you can use the following to recursively hide the file extensions in the passed in folder as arguments.


#!/bin/bash


function hide_ext () {
    # usage: $1 is folder
    #        $2 is true to hide extensions, or false to unhide them
    $(osascript <<-AppleScript
        set aFolder to POSIX file ("${1}") as alias
        tell application "Finder"
            set theFiles to (every file in entire contents of folder aFolder)
            repeat with anItem in theFiles
                set extension hidden of anItem to "${2}"
            end repeat
        end tell
        return
    AppleScript)
return
}

for f in "$@"
do
    hide_ext "$f" true
done
exit 0


Tested on macOS Mojave 10.14.6 (18G95). If you do not want the AppleScript to be folder recursive, remove the word entire from the script.

Similar questions

10 replies
Sort By: 
Question marked as Top-ranking reply

Sep 23, 2019 4:29 PM in response to EJW Tas

If you are using a Bash script within an Automator Run Shell Script, you can use the following to recursively hide the file extensions in the passed in folder as arguments.


#!/bin/bash


function hide_ext () {
    # usage: $1 is folder
    #        $2 is true to hide extensions, or false to unhide them
    $(osascript <<-AppleScript
        set aFolder to POSIX file ("${1}") as alias
        tell application "Finder"
            set theFiles to (every file in entire contents of folder aFolder)
            repeat with anItem in theFiles
                set extension hidden of anItem to "${2}"
            end repeat
        end tell
        return
    AppleScript)
return
}

for f in "$@"
do
    hide_ext "$f" true
done
exit 0


Tested on macOS Mojave 10.14.6 (18G95). If you do not want the AppleScript to be folder recursive, remove the word entire from the script.

Reply

Sep 28, 2019 6:38 PM in response to EJW Tas

The Quick Action solution that I posted on Sept. 24 will do exactly what you want to do, without adding an Ask for Finder Items action. That step is done by just right-clicking on a file/s or folder/s directly from Finder, and choosing the appropriate saved Quick Action to work on that selection.


So, I have right-clicked on a folder named Code in my home directory from within a Finder window. This presents a secondary menu, and on that menu is Quick Actions, from which I can select a saved Quick Action. I created two: one to hide file extensions, and one to show those hidden extensions again. Just polar opposites. With the Code folder selected in the Finder window, I only need to select Hide File Extensions, and it will recursively hide every file extension in the entire sub-folder hierarchy. Just what you requested. As a bonus, I added code to hide or reveal individually selected file extensions too.


Reply

Sep 27, 2019 4:17 AM in response to EJW Tas

Never give up. Own it. Solve it.


Start over from scratch with a new Automator Quick Action. Duplicate what you see in my last post. Be certain to click the hammer icon in the Run AppleScript action before you save it. I am using Dark Mode on macOS Mojave 10.14.6, so other than using Light Mode, there would be no difference in Automator functionality or results.


As I suggested, make two Quick Actions:

  1. Hide File Extensions
    1. Save…
  2. Show File Extensions
    1. Change occurrences of true to false from the first Quick Action
    2. Option + File menu : Save As…


Now, you can right-click on any file/s or folder/s — then from the secondary menu, you will see these new Quick Actions on its sub-menu as I demonstrated in the image from the previous post. Both Quick Actions are recursive when used on a folder.

Reply

Sep 24, 2019 4:21 AM in response to EJW Tas

This might be more practical. It is a Mojave Quick Action that works on individually selected file(s) and folder(s). Once the Quick Action is saved, you access it via a right click on the file or folder and choose Quick Actions > Hide Extension. You should create a copy of this Quick Action where the instances of true are changed to false, and saved as Show Extensions.


-- recursively hide file extensions in a selected folder, or on 
	-- individually selected files in the Finder
	tell application "Finder"
		repeat with anItem in input
			if kind of anItem is "Folder" then
				set theFiles to (every file in entire contents of folder anItem)
				repeat with afile in theFiles
					set extension hidden of afile to true
				end repeat
			else
				set extension hidden of anItem to true
			end if
		end repeat
	end tell
	return


and implemented in an Automator Quick Action:



and a right-click on a Folder, choosing Quick Actions from the secondary menu:



I tested this Quick Action on Mojave 10.14.6 (18G95).

Reply

Sep 28, 2019 4:20 PM in response to VikingOSX

this is as far as I can get. I pasted your text in and it looks the same as yours except the "workflow" window on top:



I have no idea/can't see any sign of any hammer icon anywhere so have no idea where to go. I have spent hours trying to read up on scripts and thought this would be easy - instead have wasted your time - sincere apologies



Reply

Sep 26, 2019 5:32 PM in response to VikingOSX

thanks Viking

I need to try again over weekend - I'm obviously too stupid to follow instructions as your screen grabs don't look anything like mine (Mojave 14.5). I'm going nuts following your guidance and my system doesn't match - a tad annoying...

sincere thanks for your efforts and assistance - greatly appreciated. Will try again over weekend and if it doesn't work, will give up and stop wasting your time

thanks again

Reply

Sep 30, 2019 11:20 PM in response to VikingOSX

got it - thanks - started from scratch and finally my screen was as you posted

I started this because Apple says Applescript is easy - I beg to differ - was programming in Fortran and other languages for 20 years, need degree for Applescript

sincere thanks for your patience and efforts

greatly appreciated


Reply

How to batch hide extensions using Automator or Finder Service?

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