English 中文(简体)
How can I write an Automator action in bash with files and folders as arguments?
原标题:

When I create a Automator action in XCode using Bash, all files and folder paths are printed to stdin.

How do I get the content of those files? Whatever I try, I only get the filename in the output.

If I just select "Run shell script" I can select if I want everything to stdin or as arguments. Can this be done for an XCode project to?

It s almost easier to use Applescript, and let that run the Bash.

I tried something like

xargs | cat | MyCommand
最佳回答

What s the pipe between xargs and cat doing there? Try

xargs cat | MyCommand

or, better,

xargs -R -1 -I file cat "file" | MyCommand

to properly handle file names with spaces etc.

If, instead, you want MyComand invoked on each file,

local IFS="
"
while read filename; do
  MyCommand < $filename
done

may also be useful.

问题回答

read will read lines from the script s stdin; just make sure to set $IFS to something that won t interfere if the pathnames are sent without backslashes escaping any spaces:

OLDIFS="$IFS"
IFS=$ 
 
while read filename ; do
  echo "*** $filename:"
  cat -n "$filename"
done
IFS="$OLDIFS"




相关问题
How to change out-of-focus text selection color in Xcode?

Okay, I ll bite. I ve got really pleasant code/window colors set up in Xcode. Ordinarily, my selection color is very visible. When I am doing a project search and iterating through the results, ...

Iphone NSTimer Issue

Hi I am new to objective c. I am trying to make an app for iphone. I have a button on my view, and the click on which the function playSound is called. This is working properly. It does plays the ...

Include a .txt file in a .h in C++?

I have a number of places where I need to re-use some template code. Many classes need these items In a .h could I do something like: #include <xxx.txt> and place all of this code in the ....

Iterating over string/strlen with umlauted characters

This is a follow-up to my previous question . I succeeded in implementing the algorithm for checking umlauted characters. The next problem comes from iterating over all characters in a string. I do ...

Xcode open two editor windows with same file

Is it possible to open the same file in two separate windows in Xcode. I can open a file in one window and the same file in the main Xcode editor window, but I wanted two separate fulltime editor ...

Forcing code signing refresh in Xcode

In our environment, we share resources across multiple projects and platforms. When building for iPhone, only a subset of those resources are needed. Since that subset is still considerable, we have ...

热门标签