Automator: trimming file path (POSIX text)

I'm trying to make what I think should be a relatively basic automator action that emails me a list of items that are new in a directory structure each day. Ideally I'd like to return the POSIX text of the file path, but reduce the path being passed to email to just this directory and subdirectories.


I've built a simple test run of this and can extrapolate it to a larger structure, but if anyone can help with this basic version, I'd appreciate it.


Here's the demo version:


User uploaded file

User uploaded file



This is what gets passed to Mail:


/Users/colin/Desktop/test/3/file3.txt

/Users/colin/Desktop/test/2/file2.txt

/Users/colin/Desktop/test/1/file1.txt


I want to remove the /Users/colin/Desktop/test/ from the above list when it is passed to mail. How do I do that?

Mac Pro, Mac OS X (10.6.8)

Posted on Sep 10, 2013 1:11 PM

Reply
8 replies

Sep 10, 2013 3:54 PM in response to Mudbug CSD

You can use a Run AppleScript action to remove the desired part of the file path:


onrun {input, parameters} -- strip file path prefix


setprefixtoPOSIX pathof(((path todesktop) astext) & "test:")-- the path prefix to strip

set output to {}



sethereto (countprefix)


repeatwithanItemintheinput

try

setendofoutputtotextherethru-1ofanItem

onerror

setendofoutputtoanItem

endtry


endrepeat



returnoutput

endrun

Sep 10, 2013 7:53 PM in response to Mudbug CSD

Yes - I didn't notice that the names were combines into a single piece of text. The following uses text item delimiters to remove all occurances of the file path prefix in the text (this also works with the various separators):


onrun {input, parameters} -- strip file path prefix


setprefixtoPOSIX pathof (((path todesktop) astext) & "test:") -- the path prefix to strip

set output to {}



settempTIDtoAppleScript's text item delimiters


repeatwithanItemintheinput

setAppleScript's text item delimiterstoprefix-- separate at prefix item

settrimmedItemstotext itemsofanItem

setAppleScript's text item delimitersto""-- recombine without prefix item

setendofoutputtotrimmedItemsastext


endrepeat


setAppleScript's text item delimiterstotempTID



returnoutput

endrun

Sep 11, 2013 10:48 AM in response to red_menace

hate to say it, but this still isn't working. Using the above, I don't get anything being passed to the new mail being created - it's just blank.


This all seems harder than it should be - is there really no way to just run a simple find/change on the text that's being passed from action to action in Automator? (I think that's basically what your script is supposed to do, but I don't read applescript well)

Sep 11, 2013 1:39 PM in response to Mudbug CSD

This is why I don't use Automator that much anymore - it is a good idea, but in practice it just acts goofy and unpredicable.


It looks like there is some kind of conversion problem when the text is passed to the New Mail Message action. One workaround I found is to save the text to a variable and immediately get the variable back. Note that if you forget to ignore the input, it doesn't get doubled up like it should (again, goofy and unpredictable).

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Automator: trimming file path (POSIX text)

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.