Finder Tags and Smart Folders

Discussion in 'OS X Mavericks (10.9)' started by Traverse, Nov 22, 2013.

  1. Traverse macrumors 603

    Traverse

    Joined:
    Mar 11, 2013
    Location:
    Here
    #1
    Hi, maybe someone here can help me with this issue.

    I'm taking several college courses and have a very complex file hierarchy in place. Before Mavericks I put all my "in use" documents (assignments and notes I am continuously using" in a folder and kept it on my Dock. When I finished my work I would put that file in its hierarchy. The problem was that I would often be lazy and not put files away when done.

    I assumed with tags I could create an "in use" tag and put the files where they belong in the first place and use the tag to find them and remove the tag when I'm done. It has worked great, but I created a smart folder to find all the "in use" tagged files so that I could put it in the dock for quick access (like a live updating folder). The problem is every time I restart my computer the folder is empty and I have to delete it and make a new one. The tags are still there and the folder works perfect...until a shutdown/restart.

    Any ideas?


    Also: (this is a less important side issue) I have a Service that copies my school documents to Dropbox for backup/archive. This creates duplicates of my tagged files. Is there any way to exclude Dropbox from tags and is there a way I can clear all tags in a folder without finding each individual folder? Thanks!
     
  2. w0lf macrumors 65816

    w0lf

    Joined:
    Feb 16, 2013
    Location:
    USA
    #2
    Sounds like a bug. Does it break if the folder is not located in the dock and you restart/shutdown?

    Don't really know anything about dropbox so I can't answer this, but you could work around this since it sounds like you know a bit about scripts.*

    Probably with xattr

    Code:
    xattr -rd com.apple.metadata:_kMDItemUserTags <folder>
    *To work around doubles due to tagging in your dropbox folder you could probably make a script that followed this flow.

    1 > copy file to temp folder
    2 > remove tag from copy
    3 > move (now untagged) copy to dropbox folder

    For simplifications sake you could probably make an application in Automator that takes dropped finder items as input and then run a script that copies, untags and moves them. Then just put the app in the dock or Finder toolbar for easy access.
     
  3. Traverse thread starter macrumors 603

    Traverse

    Joined:
    Mar 11, 2013
    Location:
    Here
    #3
    Thanks for the reply. I tested it and the Smart Folder in the Finder Sidebar works, but the Dock representation doesn't. I'll file a bug report with Apple (for all the good it will do).

    As for dropbox, I actually have limited knowledge with Automator and Scripts, but there are plenty online resources so I should be able to get that together.

    Thanks!

    Oh! And thank you for sharing the xattr resources, that looks like exactly what I need.
     
  4. Traverse thread starter macrumors 603

    Traverse

    Joined:
    Mar 11, 2013
    Location:
    Here
    #4
    Probably with xattr

    Code:
    xattr -rd com.apple.metadata:_kMDItemUserTags <folder>
    I can't seem to get this code to work...
     
  5. w0lf macrumors 65816

    w0lf

    Joined:
    Feb 16, 2013
    Location:
    USA
    #5
    Well it actually looks like some tag info is also in com.apple.FinderInfo so you get left with a general (just a tag named one of the tag colors) tag after deleting com.apple.metadata:_kMDItemUserTags. So I suppose using xattr -c is probably better.

    Here's the dropbox script:
    (Note that you need to edit the ~/Dropbox/"$FILE_NAME" to be the actual path to the dropbox folder you want to use)

    Code:
    for FILE in "$@";do
    	FILE_NAME="${FILE##*/}"
    	cp "$FILE" /tmp/"$FILE_NAME"
    	xattr -c /tmp/"$FILE_NAME"
    	mv /tmp/"$FILE_NAME" [COLOR="Red"]~/Dropbox/"$FILE_NAME"[/COLOR]
    done
    
    Here's the untag script:

    Code:
    for ITEM in "$@";do
    	if [ -d "$ITEM" ]; then xattr -rc "$ITEM"; fi
    	if [ -f "$ITEM" ]; then xattr -c "$ITEM"; fi
    done
    
    Here's an example of untagging all items on your Desktop (and sub folders)

    Code:
    xattr -rc ~/Desktop/
    Attached are both of the scripts above in workflow form.
     

    Attached Files:

  6. Traverse thread starter macrumors 603

    Traverse

    Joined:
    Mar 11, 2013
    Location:
    Here
    #6

    Thank you so much for your help! I really appreciate it!
     
  7. Traverse thread starter macrumors 603

    Traverse

    Joined:
    Mar 11, 2013
    Location:
    Here
    #7
    Please excuse my ignorance, but I can't seem to get the above codes to work correctly. Do I replace every "" with a specific name?

    Also: I did take your desktop script (thank you for telling me about it) and I modified my Copy to Dropbox script to run it (but replacing desktop with drobpox) and this seems to do what I needed (copy files/folders, but remove tags).

    If I may ask, what exactly does the xattr command remove, besides tags? Does it strip all files of all metadata? Would this cause any issues in the future?

    Sorry to sound foolish, you've been a great help.
     
  8. Traverse, Nov 27, 2013
    Last edited: Nov 27, 2013

    Traverse thread starter macrumors 603

    Traverse

    Joined:
    Mar 11, 2013
    Location:
    Here
    #8
    I'm sorry, but do you think you can help me with this:

    I didn't really like using the xattr command on my entire Dropbox folder so I tried to make the following service in Automator (check screenshot)



    The problem is, it copies to the test folder, removes the tags, but doesn't copy again to Dropbox. Do you know why?


    I guess what I'm looking for is a right-click service that will copy the file/folder to Dropbox while removing the tag. I'm just not sure how I would set up that service..

    Would just using my previous xattr service on my entire dropbox ever hurt a file? I just don't know what xattr really does..(yes, i googled it, but will removing extended attributes cause issues?)
     

    Attached Files:

  9. w0lf macrumors 65816

    w0lf

    Joined:
    Feb 16, 2013
    Location:
    USA
    #9
    I'm sorry I didn't explain too well but you want to take the scripts I posted and convert them to either a service or an app using automator.

    Here's how to make a service from a workflow with automator:
    1 > Open the workflow
    2 > File > Convert to...
    3 > Select service
    4 > Set up your inputs
    5 > Save
    6 > You might have to then close and reopen the service and Automator will offer to install it (basically just move it to ~/Library/Services/)

    Also removing extended attributes won't hurt your file/folder in any way. Think of it like deleting album art and metadata from an mp3. I'm not entirely sure of all the things finder stores there but the two I know for certain are tags and custom icons.

    No the quotes are there to keep whitespace from breaking the script.

    eg: ~/bob/my cat/taco.jpeg is not the same as ~/bob/"my cat"/taco.jpeg or ~/bob/my\ cat/taco.jpeg the first one would read as two separate arguments rather than one string. A \ can be used to escape white space but putting something in quotes works too.

    Here's an example (slightly changed from my last post to handle folders):
    [​IMG]

    The only thing in the script you might want to change is the destination folder ~/Dropbox/"$FILE_NAME" which you could for example change to ~/Dropbox/Completed\ Work/"$FILE_NAME" or something akin to that if you don't want to be just dumping everything in your base dropbox folder.

    Here's a video of it in action

    Here's the service itself
     
  10. Traverse thread starter macrumors 603

    Traverse

    Joined:
    Mar 11, 2013
    Location:
    Here
    #10
    Thank you so much! You're awesome, I mean it!
     
  11. Traverse, Nov 28, 2013
    Last edited: Nov 28, 2013

    Traverse thread starter macrumors 603

    Traverse

    Joined:
    Mar 11, 2013
    Location:
    Here
    #11
    Your service worked perfectly!

    I really appreciate this. If I could pay you I would!
    _________
    There is one odd thing though:
    My old service replaced the folder (and accompany files) so I could just keep updating it. Your service creates a new folder within the existing one in Dropbox.

    Example: First Time I save FOLDERX to Dropbox it works perfectly (copies all content with no tags)
    Second Time I save it, a new updated FOLDERX appears inside the old FOLDERX taking up more space.


    You've already helped me so much, so please don't be annoyed with me. I can easily work around this problem by trashing the first file, but if there is an easy fix just let me know if you have time.

    Again, thank you.
     
  12. w0lf macrumors 65816

    w0lf

    Joined:
    Feb 16, 2013
    Location:
    USA
    #12
    Yup that definitely happens, surprised I didn't notice that before posting.

    This avoids that:

    Code:
    for FILE in "$@";do
    	FILE_NAME="${FILE##*/}"
    	if [ -d "$FILE" ]; then 
    		rsync -rut "$FILE"/ /tmp/"$FILE_NAME"
    		xattr -rc /tmp/"$FILE_NAME"
    		rsync -rut /tmp/"$FILE_NAME"/ ~/Dropbox/"$FILE_NAME"
    		rm -r /tmp/"$FILE_NAME"/
    	else
     		rsync -ut "$FILE" /tmp/"$FILE_NAME"
    		xattr -c /tmp/"$FILE_NAME"
    		rsync -ut /tmp/"$FILE_NAME" ~/Dropbox/"$FILE_NAME"
    		rm /tmp/"$FILE_NAME"
    	fi
    done
    
     
  13. Traverse thread starter macrumors 603

    Traverse

    Joined:
    Mar 11, 2013
    Location:
    Here
    #13

    Thank you so much! You've really helped me out!
     

Share This Page