hiding certain file extensions

Discussion in 'Mac OS X Lion (10.7)' started by tildesley, Jan 1, 2012.

  1. tildesley macrumors regular

    Joined:
    Jan 8, 2009
    #1
    hi

    i was wondering how i would go about hiding files with an certain extension, for example. i have a number of *.avi files on a networked drive (HFS+), to get these to show correctly on my JB ATV2, you can create thumbnails, these have to sit in the same folder, so I want to hide *.tbh extensions, i've watched a few videos on how to hide folders but it doesn't really give any assistance on hiding files, also I would rather do it as a batch rather than 1 by 1, would automator or apple script help here?

    seasons greetings

    jt
     
  2. Partron22 macrumors 68000

    Partron22

    Joined:
    Apr 13, 2011
    Location:
    Yes
    #2
    This Applescript should do it for you:
    Code:
    --  Toggle visibility of files having a chosen extension type in a folder
    --  Run script once to hide, and again to show
    --  Also includes lines for setting all files visible, or all invisible.
    --  BP 2012
    --••••••••••••••••••••••••••••••••••••••
    set targetFileExtension to ".scpt" -- Set this to the extension you want to hide. ⬅#
    --••••••••••••••••••••••••••••••••••••••
    tell application "Finder"
    	set targfolder to (choose folder) as text
    end tell
    
    -- Get the names of files in folder, hidden or not:
    set targpath to quoted form of POSIX path of targfolder
    set zed to do shell script "ls " & targpath -- bypassing the Finder
    
    -- Massage shell script data into a proper list:
    set oldtid to AppleScript's text item delimiters
    set AppleScript's text item delimiters to "\r"
    set tlst to every text item of zed -- every file in folder (except UNIX invis)
    set AppleScript's text item delimiters to oldtid
    
    -- Toggle each files hidden status
    repeat with n from 1 to count of tlst
    	if item n of tlst contains targetFileExtension then
    		set targpath to POSIX path of (targfolder & item n of tlst)
    		tell application "System Events" to set viz to visible of disk item targpath
    		tell application "System Events" to set visible of disk item targpath to not viz
    		
    		-- Comment out the line above, and uncomment one of the lines below to set
    		-- the visible status of everything in a folder to the same value
    		
    		--tell application "System Events" to set visible of disk item targpath to true
    		--tell application "System Events" to set visible of disk item targpath to false
    	end if
    end repeat
    
    return tlst
    
     

Share This Page