• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: do shell script problem with files with spaces in the name
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: do shell script problem with files with spaces in the name


  • Subject: Re: do shell script problem with files with spaces in the name
  • From: Joe Block <email@hidden>
  • Date: Mon, 16 May 2005 00:25:33 -0400


On May 15, 2005, at 8:02 PM, Mike Ashley wrote:

On May 15, 2005, at 5:03 PM, Joe Block wrote:
Here are the details of the workflow I created to process a folder tree and run a unix command on each file in the tree.

Step 1: Get Selected Finder Items
Step 2: Get Folder Contents, with "repeat for each subfolder found" checked
Step 3: Run shell script with "Use input as arguments" checked.


The shell script is a simple ruby script, testit.rb (source follows):

-- cut --
#!/usr/bin/ruby

ARGV.each {|arg| puts arg}

-- cut --

If I open a terminal window and invote testit.rb as

testit.rb /path/to/dir/with/files/with/spaces/in/the/names/*

it correctly prints all the file names, including the ones with spaces in them, one per line.

Once I add it testit.rb to the workflow however, Automator chops up the filenames, and if I have a file named "one two three", the "one", "two" and "three" show up as separate lines of output.

Am I doing something wrong here, or is Automator's handling of filenames broken?

I was able to make this work, but I needed to use an applescript action to quote the filenames. I've attached my workflow as an example, and here is the script.


on run {input, parameters}
    set output to {}
    repeat with i from 1 to length of input
        set x to item i of input
        set output to output & {quoted form of POSIX path of x}
    end repeat
    return output
end run

You can't expect the do shell script action to quote the filenames, since in general the do shell script action doesn't know what will be done with the input it's passed. You might argue that if it's passed aliases, it should do the 'quoted form of' in addition to converting to POSIX names. It's still not clear to me that's always right, though.

Thanks for the applescript, it takes care of the problem handily. I think that when passed aliases, the do shell script command should convert them to quoted form since that's what shell scripts are going to expect.


jpb
--
Joe Block <email@hidden>

"She's the kind of girl who climbed the ladder of success wrong by wrong."
- Mae West

Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Automator-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >do shell script problem with files with spaces in the name (From: Joe Block <email@hidden>)
 >Re: do shell script problem with files with spaces in the name (From: Mike Ashley <email@hidden>)

  • Prev by Date: Encrypted archives?
  • Next by Date: Re: do shell script problem with files with spaces in the name
  • Previous by thread: Re: do shell script problem with files with spaces in the name
  • Next by thread: Re: do shell script problem with files with spaces in the name
  • Index(es):
    • Date
    • Thread