Tuesday, February 25, 2020

#1 2010-04-06 12:15:55 pm

L1ONE
Member
Registered: 2010-04-06
Posts: 3

Applescript for Hiding Files?

Hi, I want to Hide a certain file type as soon as they are created. The file type in question is .asd files.

I had this all configured with Automator, Apple Scripts and Folder Actions, however I'm running into a few bugs and wonder if anyone can suggest better ways of doing it.

Here's what I currently have.

Automator App ---

It has a Run Shell Script attached with the following command...

find /Users/Luke/Music Production/* -iname *.asd -execdir chflags hidden {} ;

This is the code to hide the files in the Music Production directory and sub directories.


Apple Script ---

Applescript:

on adding folder items to this_folder after receiving added_items
tell application "Mac OS X:Users:Luke:Library:Workflows:Applications:Folder Actions:Hide Live Files.app"
open added_items
end tell
end adding folder items to

This will be the script that is run when a file is added to the directory, however I would like this to affect all sub directories as well.


Folder Action ---

This is where It gets annoying because it only affects the main directory and not sub directories.

I attached the Apple Script I created to the /Music Production/ directory but when files are added to sub directories nothing happens. There are about 400 sub directories here and it would be **** to attach folder actions to each of them.


I think a way round this would be to make an Apple Script to add Folder Actions to all sub-directories. It would be a one off script that I'd have to run, Unless I can get it automated somehow.

How would I code something like that?

Any help would be appreciated.

Last edited by L1ONE (2010-04-06 12:16:52 pm)

Offline

 

#2 2010-04-06 02:54:24 pm

Trash Man
Sanitation Department
Registered: 2005-10-20
Posts: 5336

Re: Applescript for Hiding Files?

You can easily loop through subfolders/-files with a recursive handler.

Applescript:


on run
   set s to choose file with prompt "Choose the script file"
   set f to choose folder "Choose the top level directory"
   
   addActionToFolderAndSubfolders(f, s)
end run

on addActionToFolderAndSubfolders(startFolder, scriptPath)
   -- code for adding the folder item
   tell application "System Events" to attach action to startFolder using scriptPath
   
   tell application "Finder" to set allFolders to every folder of startFolder
   repeat with i in allFolders
       addActionToFolderAndSubfolders((i as alias), scriptPath)
   end repeat
end addActionToFolderAndSubfolders

Hope it helps,
ief2

Last edited by ief2 (2010-04-06 02:55:09 pm)


One mans trash is another mans treasure

Offline

 

#3 2010-04-06 03:58:10 pm

L1ONE
Member
Registered: 2010-04-06
Posts: 3

Re: Applescript for Hiding Files?

ief2 wrote:

You can easily loop through subfolders/-files with a recursive handler.

Applescript:


on run
   set s to choose file with prompt "Choose the script file"
   set f to choose folder "Choose the top level directory"
   
   addActionToFolderAndSubfolders(f, s)
end run

on addActionToFolderAndSubfolders(startFolder, scriptPath)
   -- code for adding the folder item
   tell application "System Events" to attach action to startFolder using scriptPath
   
   tell application "Finder" to set allFolders to every folder of startFolder
   repeat with i in allFolders
       addActionToFolderAndSubfolders((i as alias), scriptPath)
   end repeat
end addActionToFolderAndSubfolders

Hope it helps,
ief2


Hi, thanks looks as if it would work, just a quick question do I need to change anything in this? Sorry I'm a big noob at all of this

Offline

 

#4 2010-04-06 04:01:00 pm

Trash Man
Sanitation Department
Registered: 2005-10-20
Posts: 5336

Re: Applescript for Hiding Files?

nope, don't think so. It will ask for a folder and the script file which you should have saved on the hard somewhere.


One mans trash is another mans treasure

Offline

 

#5 2010-04-06 04:18:41 pm

L1ONE
Member
Registered: 2010-04-06
Posts: 3

Re: Applescript for Hiding Files?

ief2 wrote:

nope, don't think so. It will ask for a folder and the script file which you should have saved on the hard somewhere.


Thanks all worked perfect, took ages to render or whatever though, but thats probably having 1000s of folders.

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)