Automator: trimming file path (POSIX text)

Discussion in 'Mac Programming' started by Mudbug, Sep 10, 2013.

  1. Administrator emeritus

    Mudbug

    Joined:
    Jun 28, 2002
    Location:
    North Central Colorado
    #1
    Hi everyone -
    I've posted this in the apple discussions forum, but thought I might get faster help here. (http://discussions.apple.com/thread/5298918) If you can help there instead, that would work just as well.
    [​IMG][​IMG]

    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? (it's probably right in front of me...)
     
  2. macrumors 68040

    Joined:
    Feb 2, 2008
    #2
    You can probably exchange the "get names of finder items" action with "run shell script" and this content:

    Code:
    for f in "$@"
    do
    	echo "$f" | sed 's/\/Users\/colin\/Desktop\/test\///g'
    done
    
    Also, select "as argument" in the upper right corner drop down menu.

    Keep in mind that the file path is specific to your environment, and hard coded here, so if you move the files or run it on a different computer it will probably not work without modifications.
     

Share This Page