Script for extension-hide at folder-level

Discussion in 'Mac Programming' started by Vaakuna, Dec 30, 2015.

Tags:
  1. Vaakuna macrumors newbie

    Vaakuna

    Joined:
    Dec 30, 2015
    Location:
    Finland
    #1
    Hi, Applers.

    I have taken note of a 2015 script published here on MR by w0lf (and will reference the like below) but wanted to tweak it; I am in need of a similar Terminal-script but more parochial.

    I want only to hide all extensions in my Music folder (which is GB140 and peppered with mp3 and wma suffixes too great to engage on an item-by-item level) and cannot check/uncheck at the folder-level the CMD-i/CMD-ALT-i option for "Hide extension" no matter what I try.

    Below is w0lf's HDD-universal script and I would like someone in the know to confirm it would work if I rewrite the line ...for item in $1... as ...for item in "€HOME"/Music...?

    (NB Must locative elements of scripts be in English language or language that the MBP operates in? E.g. there are no folders called Documents, Pictures, Music et cetera on my computer)

    **Begin w0lf's instruction**
    1. Open Terminal
    2. Install the Xcode command line tools with this line

    3. Code:
      xcode-select --install

    4. Run these commands

      Code:
      cd ~/Desktop
      touch hide_ex.command
      open -e hide_ex.command

    5. Paste this and save the file

      Code:
      #! /bin/bash

      #
      # Hide extensions script
      # Hides all extensions on all files for all user accounts
      # Requires Xcode command line tools for SetFile
      # By : w0lf
      #

      rr() {
      for item in "$1"/*; do
      if [[ -d "$item" ]]; then
      echo "Entering directory: $item"
      rr "$item"
      elif [[ -w "$item" ]]; then
      echo "Hiding extension for: $item"
      SetFile -a E "$item"
      fi
      done
      }

      rr /Users
      tput bel

    6. Back in terminal run

      Code:
      chmod 755 hide_ex.command
      ./hide_ex.command

    7. Every file affected will be printed out to terminal, you can minimize terminal and when it's finished you'll hear a ding sound and your minimized terminal window will get a notification badge.
    8. If you even want to run it again all you have to do is open the file you created which will be on your desktop.
    **End w0lf's instruction**

    Thanks, everyone.
     
  2. leman macrumors 604

    Joined:
    Oct 14, 2008
    #2
    From what I can see you should change the line

    rr /Users

    to

    rr $HOME/Music

    That said, the script is unnecessary complicated. You can simply do (untested)

    find $HOME/Music -type f -exec SetFile -a E {} \;
     
  3. Vaakuna thread starter macrumors newbie

    Vaakuna

    Joined:
    Dec 30, 2015
    Location:
    Finland
    #3
    Thanks, leman; I will try this today, but do I need before still to input at Terminal the following:

    xcode-select --install

    So would the input be two lines and look like this:

    xcode-select --install
    find $HOME/Music -type f -exec SetFile -a E {} \

    and must the word HOME be in English or in the language of the computer?
     
  4. leman macrumors 604

    Joined:
    Oct 14, 2008
    #4
    First of all a disclaimer: I deny any responsibility if your computer goes up in flames or your data is lost :) I haven't tested the script and I never worked with the SetFile command. I recommend you to back up all your stuff before you mess around with terminal.

    To your questions: what xcode-select --install does it install development command line tools for OS X. You need them for the SetFile command. I am sure there is a way to do the same without this command, but I never looked into it, so I don't know. You only need to do xcode-select --install once — if the tools are already installed on your computer, you can skip that test.

    Second, $HOME is the built-in variable that holds the location of your home folder. The name of the variable does not depend on the language of your computer. You can also use /Users/your_user_name/Music to the same effect (replace your_user_name by the name of your user folder).

    Finally, my recommendation to you is to take some time and work though a unix/linux command line tutorial. You can easily mess up important stuff when you dabble in the command line without understanding what things do. The basics are very easy to learn and you will benefit greatly from them.
     
  5. Vaakuna thread starter macrumors newbie

    Vaakuna

    Joined:
    Dec 30, 2015
    Location:
    Finland
    #5
    @leman

    I hereby relinquish you of responsibility should I engulf my computer or self in flames of error. ;)

    I will search for a tutorial and then commit to this. Again, thank you very much. I'll post if my successes are to great fame and fortune.
     

Share This Page