Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Feb 14, 2013, 12:17 PM   #1
tedesco24
macrumors member
 
Join Date: Jul 2010
Folder Action to spotlight and copy

I'm hoping this is a better way to find help vs hours spent on google.

I want to set up a Folder Action to accomplish the following:

I scan a pdf to my desktop, drag and drop the pdf to the subfolder labeled "2013"

The Folder Action should fire up and:
1. Add a spotlight comment
2. Copy the modified pdf, with the updated spotlight comment, to an external drive.
3. Copy the modified pdf, with the updated spotlight comment, to the cloud (this is icing on the cake, so not vital to the workflow)

I've created a few Folder Actions but can't quite get the workflow to be consistent.

Thanks
__________________
Bill
Aluminum Macbook Pro mc372ll/a
iPhone and iPod Nano
We all have a choice, choose life and honor Him!
tedesco24 is offline   0 Reply With Quote
Old Feb 14, 2013, 04:06 PM   #2
chown33
macrumors 603
 
Join Date: Aug 2009
Post what you have now.

Please explain what you mean by "can't quite get the workflow to be consistent". Do you mean it consistently doesn't work? It inconsistently works? Some sub-part works inconsistently? The copied data is inconsistent (i.e. not identical) to the original?
chown33 is offline   0 Reply With Quote
Old Feb 14, 2013, 10:54 PM   #3
tedesco24
Thread Starter
macrumors member
 
Join Date: Jul 2010
Thank you for taking an interest and trying to help.

Here is my current Folder Action:

Folder Action receives files and folders from (DESKTOP FOLDER)
1. Set Spotlight Comments for Finder Items
Append to Existing Docs and Show This Action are checked

2. Find Finder Items (IGNORE INPUT)
Search (DESKTOP FOLDER)
ALL of the following are true
ANY Content
3. Filter Finder Items
All of the following are true
Kind is not Folder (did this so that the file copies, not the folder)
Date created is today (only want to copy the most recent file, not the entire folder contents)
4. Copy Finder Items
To (EXTERNAL DRIVE)

The only problem I'm having is the Spotlight Comments are not showing up on the file that is landing on my External Drive. The file gets there but the Spotlight Comments are missing. Any ideas why?
__________________
Bill
Aluminum Macbook Pro mc372ll/a
iPhone and iPod Nano
We all have a choice, choose life and honor Him!
tedesco24 is offline   0 Reply With Quote
Old Feb 15, 2013, 12:25 AM   #4
chown33
macrumors 603
 
Join Date: Aug 2009
I don't know why the comments wouldn't be on the copy. Maybe it's the timing. That is, the copy occurs too close on the heels of setting the comment, so either Finder fails to copy it, or Spotlight loses it.

A possible solution is to not add the comment to the original file in Desktop folder, but to add the comment on the copy, after it's been copied, on the external HD.
chown33 is offline   0 Reply With Quote
Old Feb 15, 2013, 11:07 AM   #5
kryten2
macrumors 6502a
 
Join Date: Mar 2012
Location: Belgium
Why don't you try a simple workflow with only the Set Spotlight Comments for Finder Items action. Attach it to your 2013 folder and drop a pdf in it. See if the comment is set. We are talking about Automator workflows here right? Also what version of OS X are you running? I'm guessing it's Leopard.
__________________
Space Corps Directive 34124
kryten2 is offline   0 Reply With Quote
Old Feb 15, 2013, 02:41 PM   #6
tedesco24
Thread Starter
macrumors member
 
Join Date: Jul 2010
Chown...I also was thinking it was a timing issue. I messed around and added a Pause action. That didn't solve the problem.

Kryten...I'm running ML. I've re-built the workflow step by step so I can hopefully figure out where the error is. The only thing not working is retaining the Comments on the file being copied to the external drive.

Im about 90% finished with a Hazel workflow to handle this but I'd prefer a Folder Action that I can slap on all of my folders versus setting up Hazel rules for all of the folders that need the workflow (about 40 folders).
tedesco24 is offline   0 Reply With Quote
Old Feb 15, 2013, 02:59 PM   #7
chown33
macrumors 603
 
Join Date: Aug 2009
A file's comment is stored in a named xattr. You can list the names with the command 'ls -l@ filename'. Then you can use the 'xattr' command to show the value of the xattr, write it, delete it, etc. See 'man xattr'.

I would break this down into individual steps, starting with putting the comment on the file. Confirm that works using an Automator action that runs a shell script, and in that script use 'xattr' with appropriate options to list and show whether the file really has a Finder comment. If the xattr for the comment doesn't show up, then you've isolated the failing step.

Since 'xattr' can also write xattrs, you could use it to attach a comment, but it would take quite some effort to get the data in the right format (a binary plist, or "bplist") to work with 'xattr' as a shell command.


BTW, if it's not a timing issue, maybe it's a caching issue. The 'sync' command will flush everything to disk. I don't think this is the cause, but it's worth a shot.

Personally, I think Finder is just out of sync. It doesn't see the change, or doesn't think it needs to resync, so it doesn't copy the xattr. I've seen plenty of Finder bugs in Mtn Lion where things change in the file-system but Finder doesn't see it. This could easily be one of those.

If the 'xattr' cmd does show a comment, but Finder still fails to copy it, you should be able to use the 'cp' command to copy. Since at least OS X 10.6, 'cp' has been aware of resource-forks, xattrs, etc. and will copy them. Another command that's aware of these extras is 'ditto', so 'man ditto'.
chown33 is offline   0 Reply With Quote
Old Feb 17, 2013, 12:51 PM   #8
tedesco24
Thread Starter
macrumors member
 
Join Date: Jul 2010
whoa, you went all Nick Burns on me.

My desired Folder Action seems rather basic, I'm really surprised there isn't a pre-made Action to accomplish this.

Anyways, it seems the more I play with this, the more frustrating it gets. Right now my spotlight comments are only sticking with the file once it lands in the Desktop folder. But once I add any additional action to the workflow (MOVE THE FINDER ITEM or COPY THE FINDER ITEM or RENAME THE FINDER ITEM, etc), the comments disappear.

Any suggestions on how to build this from the ground up? Could it be related to the file is being moved from a root folder to a subfolder? I've only been using the ACTION commands, should I look into using VARIABLES?
__________________
Bill
Aluminum Macbook Pro mc372ll/a
iPhone and iPod Nano
We all have a choice, choose life and honor Him!
tedesco24 is offline   0 Reply With Quote
Old Feb 17, 2013, 02:22 PM   #9
chown33
macrumors 603
 
Join Date: Aug 2009
Quote:
Originally Posted by tedesco24 View Post
My desired Folder Action seems rather basic, I'm really surprised there isn't a pre-made Action to accomplish this.
I'm not surprised at all. You described the sub-actions yourself:
1. Add a spotlight comment
2. Copy the modified pdf, with the updated spotlight comment, to an external drive.
3. Copy the modified pdf, with the updated spotlight comment, to the cloud.
Each of those things is an Action. Why would there be a pre-made one that did them all?


FWIW, the non-copying of the comment seems like a bug to me. Trying to wish it away won't work. You have to come up with a way to work around it if you hope to accomplish the final goal. It's not magic; it's programming.


Quote:
Any suggestions on how to build this from the ground up? Could it be related to the file is being moved from a root folder to a subfolder?
Since the problem seems to be that a comment is not being copied, try doing the copying first, and the comment attachment last.

Your original sequence:
  1. Add a spotlight comment
  2. Copy the modified pdf, with the updated spotlight comment, to an external drive.
  3. Copy the modified pdf, with the updated spotlight comment, to the cloud.

Rearranged sequence:
  1. Copy the pdf to an external drive.
  2. Add a spotlight comment to the copy.
  3. Copy the modified pdf, with the updated spotlight comment, to the cloud .

Or if you need the original to have the same comment:
  1. Add a spotlight comment to the original.
  2. Copy the pdf to an external drive (losing its comment).
  3. Add a spotlight comment to the copy on the external drive.
  4. Copy the original (or the duplicate on the external drive) to the cloud.


Quote:
I've only been using the ACTION commands, should I look into using VARIABLES?
What do you think that will change?

If you've never used Automator variables, or don't know how they work, then I think learning them is a useful added skill. But if you're learning them in the hopes of magically fixing the bug, I suspect you'll be disappointed.
chown33 is offline   0 Reply With Quote
Old Feb 17, 2013, 07:26 PM   #10
kryten2
macrumors 6502a
 
Join Date: Mar 2012
Location: Belgium
Can you try this script. Run it from Script Editor.

Code:
set these_items to choose file with prompt "Choose file you wish to comment : " with multiple selections allowed without invisibles
repeat with anItem in these_items
	tell application "Finder" to set {theComment, theContainer, theName} to {comment, container, name} of anItem
	if theComment is "" then
		set theNewComment to text returned of (display dialog "Folder : " & theContainer & return & "Name : " & theName & return & "Comment : " & theComment & return & return & "Type in the comment you would like to add to the " & theName & " file." with title "Adding Spotlight Comments" default answer "" buttons {"OK"} default button 1)
		tell application "Finder" to set anItem's comment to theNewComment
		set theDestination to (choose folder with prompt "Copy " & theName & " to : ")
		tell application "Finder" to set theCopiedItem to duplicate anItem to theDestination
		tell application "Finder" to set {theCopiedComment, theCopiedContainer, theCopiedName} to {comment, container, name} of theCopiedItem
		display dialog "Folder : " & theCopiedContainer & return & "Name : " & theCopiedName & return & "Comment : " & theCopiedComment with title "Display Copied Item Spotlight Comments" buttons {"OK"} default button 1
	else
		display dialog "Folder : " & theContainer & return & "Name : " & theName & return & "Comment : " & theComment with title "Display Current Spotlight Comments" buttons {"OK"} default button 1
	end if
end repeat
Attached Thumbnails
Click image for larger version

Name:	Picture 1.png
Views:	25
Size:	35.4 KB
ID:	397621   Click image for larger version

Name:	Picture 3.png
Views:	25
Size:	27.8 KB
ID:	397622  
__________________
Space Corps Directive 34124
kryten2 is offline   0 Reply With Quote
Old Feb 18, 2013, 08:45 AM   #11
tedesco24
Thread Starter
macrumors member
 
Join Date: Jul 2010
Chown and Kryten, thank you both for helping. I'll play with both solutions later today.

I've never programmed anything more complex than my VCR in the 80's, so this as all foreign to me. It's a "learn as I go" process.

Enjoy the day.
__________________
Bill
Aluminum Macbook Pro mc372ll/a
iPhone and iPod Nano
We all have a choice, choose life and honor Him!
tedesco24 is offline   0 Reply With Quote
Old Feb 22, 2013, 10:07 AM   #12
tedesco24
Thread Starter
macrumors member
 
Join Date: Jul 2010
Thank you for the suggestions. I played around with them, added a few tweaks, and got the Folder Action to work as desired.

Here's the workflow for anybody that might be looking for something similar.

Folder Action receives files and folders added to "DESKTOP FOLDER A"

1. REPLACE TEXT - Show this action
2. SET SPOTLIGHT COMMENTS FOR FINDER ITEMS -append to existing-show this action
3. COPY FINDER ITEMS to "EXTERNAL DRIVE FOLDER A"
4. SET SPOTLIGHT COMMENTS FOR FINDER ITEMS - show this action- (DO NOT check "append" or you will have duplicate comments)

This works exactly as I needed it to.

I can scan a pdf to my desktop and give it a generic name such as "z 1". I'll then drop the pdf file in the appropriate folder on my desktop. This FOLDER ACTION recognizes the pdf and gives me the option to rename the file to something specific, add the spotlight comments, and copy the finished file to my external drive. The finished file ends up in both my desktop folder and external drive folder, perfectly synced with the name and comments! I imagine I could duplicate steps 3-4 and add another location (the cloud?) but that would be overkill for what I need.
__________________
Bill
Aluminum Macbook Pro mc372ll/a
iPhone and iPod Nano
We all have a choice, choose life and honor Him!
tedesco24 is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Accidentally tried to copy a folder to a sub-folder within it.. Original folder Gone samth3mancgp OS X 10.8 Mountain Lion 4 Sep 9, 2014 10:40 PM
Folder Action Setup not working Callum Mac Basics and Help 1 Jan 22, 2014 10:15 PM
Triggering folder action on dropbox folder? ronswanson Mac Programming 3 Aug 7, 2013 04:39 PM
Action Folder in /Volumes/ DKnow75 Mac Programming 5 Jun 15, 2013 08:12 AM

Forum Jump

All times are GMT -5. The time now is 04:51 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC