Automator Hidden Folder Action For /.Trash

Discussion in 'Mac Apps and Mac App Store' started by j.drake.hoffman, Jul 19, 2010.

  1. j.drake.hoffman macrumors newbie

    Joined:
    Aug 20, 2009
    Location:
    right here
    #1
    So, I'm trying to add a relatively basic folder action to the hidden trash folder. Generally what i'm trying to achieve is 2-way syncing between *.txt files on my desktop and Dropbox -- i use them for notes. (btw, if you dont have Dropbox, its free online storage that can be synced across multiple computer. check out this link to get us both bonus space!) So far, I have workflows for moving *.txt files to a certain Dropbox folder and for creating a symbolic link (alias?) to my desktop.

    What I'm looking to figure out how to do is attach a folder action to the .Trash folder so if I delete the file or the link, the other will also be put into the trash. It seems to me that my problem is that there does not seem to be an obvious way to add a folder action to a hidden folder.

    If anyone has any ideas, I would be extremely grateful!

    Thank you in advance.

    (btw, if anyone wants the procedure for making what I have now, just respond or pm me or something. its not hard to do what i have so far... also, i think this would be the appropriate forum [instead of software dev.])
     
  2. j.drake.hoffman thread starter macrumors newbie

    Joined:
    Aug 20, 2009
    Location:
    right here
    #2
    ok, so i figured out how to add a folder action to a hidden folder and how to refer to them for automator, but now, the question remains, how do I use a file name of a file being input to a folder as a search criteria for finding a file in another folder?
     
  3. j.drake.hoffman thread starter macrumors newbie

    Joined:
    Aug 20, 2009
    Location:
    right here
    #3
    The Solution!

    For anyone coming across this thread looking for something similar to what i was trying to do, I have a solution!

    While Automator can take care of moving files between folders well enough, the "Filter Finder Items" and "Find Finder Items" didn't really work as I wanted for the .Trash folder. I found a solution was to write several shell (bash) scripts to get the job done. (after having wrote the folder actions to have the files and their aliases moved around as I desired -- shouldn't be too difficult to figure out)

    The first script is for when one wants to delete an alias and have its corresponding file moved to the trash. Make it a service in Automator -- make it receive FILES OR FOLDERS, IN ANY APPLICATION, and pass input AS ARGUMENTS. Those things are important! (especially the 1st and last) The script is as follows:


    Code:
    for f in "$@"
    do
    	source_path="$f"					#location of alias
    	file_name=${source_path##*/}		#isolating the name of the file
    	semi_path="/Volumes/Stor/Users/johnhoffman/Dropbox/Notes/"	#path to real file
    	full_path=$semi_path$file_name		#constructing path to file to delete
    	cp "$full_path" /Volumes/Stor/Users/johnhoffman/.Trash/		#copies text file to trash
    	rm "$full_path"						#remove text file at original location
    	rm "$f"								#remove alias to text file
    done
    You would need to change the 3rd line of the indented text to be the directory where the real text file is. likewise, you would also need to change the 5th line to be the path to your Trash (most likely just replace "johnhoffman" with your login name. the comments should explain what the steps do. The name you use to save it will be what appears when you right-click on file(s)/folder(s). I chose "Obliterate!"

    The next script deals with the possibility that one of the files in your Dropbox may be deleted elsewhere. (also that if a file is autosaved, another alias will be created...) As I find it unsightly to have broken aliases on my extremely organized Desktop, (insert sarcasm here...) the next script will hunt down and kill all those broken aliases. It is as follows:

    # gets aliases as a string with each file separated by a newline
    files_string="$(find -L ~/Desktop -type l)"

    Code:
    IFS=$'\n'			# set 'Internal Field Separator' to be the newline
    
    file_arr=( $files_string )			# create array of file-paths
    
    for f in "${file_arr[@]}"			# removing the files
    do
    	rm "$f"					# ZERSTÖREN!!!!
    done
    
    exit 01
    You may also nee to change ~/Desktop to the directory you wish to scan, if its not the desktop. Now, this next part might be tricky, bc after writing it, you need to know where you saved the script. (if you dont know how to do scripting, there are plenty of guides online how to do it -- I'll leave the instructions to those bc they are less than counterintuitive...) After having written the script, you'll have to to set it up in crontab. If you're afraid of the command line, look up Cronnix.app. If not, just look up crontab online.

    Thats it! It should now be set up to auto-move and delete.
     
  4. Adam.K macrumors newbie

    Joined:
    Sep 20, 2013
    #4
    Thanks

    Thanks (3 years later!) for posting this. I haven't tried it yet but thanks for making the effort to share knowledge.
     

Share This Page