|
|
#1 |
|
Prospect
Join Date: Jul 2011
Posts: 9
|
Hello there,
basically what I want to do is in my eyes not very complicated but I am not coming around one "simple" problem. Basically what I am doing > get files from finder action > get path of files action > get unix path of files > save this into a variable. the output until this point is: "/test/test/test1.jpg""/test/test/test2.jpg""/test/test/test3.jpg" So far so good. Everything what is between me and my goal: missing spaces between those paths. The result should look like this: "/test/test/test1.jpg" "/test/test/test2.jpg" "/test/test/test3.jpg" I need the spaces because otherwise the shellscript I am triggering afterwards will not recognise the paths correctly. Anybody has a hint for me how to modify the variable to get the output I need? Everthing I tried and found via google did not work :/ Thanks in advance |
|
|
|
|
|
#2 |
|
Site Admin
Join Date: Jan 2002
Location: Montreal
Posts: 31,939
|
Perhaps the discussion of list separators here:
http://daringfireball.net/2003/02/sa...re_safari_urls will be of use.
__________________
hayne.net/macosx.html |
|
|
|
|
|
#3 | |||||||||||||||||||
|
Prospect
Join Date: Jul 2011
Posts: 9
|
Hello Hayne,
you definitly are my hero of the day for that link! I spend hour after hour and really was frustrated. Now had a look, read the page and this is what I got:
And it worked like it should Wonderful. Many thanks!!!
|
|||||||||||||||||||
|
|
|
|
|
#4 |
|
Prospect
Join Date: Jul 2011
Posts: 9
|
Well, I was to happy as it seems.
It works when I am using the "step-by-step" functionality within automator but when I am using the workflow in finder the string "/test/test/test1.jpg" "/test/test/test2.jpg" "/test/test/test3.jpg" gets to /test/test/test1.jpg /test/test/test2.jpg /test/test/test3.jpg which is bad if there are spaces within the path :/ Any idea why this is happening ? |
|
|
|
|
|
#5 |
|
Site Admin
Join Date: Jan 2002
Location: Montreal
Posts: 31,939
|
You'll need to escape the quotes so they get preserved until needed, or (more reliable) break up the string into separate paths and then create the final string for your shell script as needed.
__________________
hayne.net/macosx.html |
|
|
|
|
|
#6 |
|
MVP
Join Date: Apr 2008
Location: Berkeley CA USA
Posts: 1,009
|
If you tread down the path of escaping quote marks, you'll quickly find yourself in a morass. What do you do with paths that contain quote marks? You need to escape those, too. But if you escape them with backslashes, what do you do with paths that contain backslashes? It might be easier to use single quotes, but then you still have to deal with paths that contain single quotes.
Fortunately, you don't have to deal with any of that. "quoted form of ..." is your friend. It'll take care of all the messy quoting rules. Automator and AppleScript usually prefer to deal with (lists of) aliases or HFS-style paths, in which colon is the path separator and slash is a normal character; Unix uses POSIX-style paths, where slash as the path separator and colon as a normal character. The fix is to exchange those two characters before passing a path to the shell. But there's also a difference in how they distinguish relative from absolute paths. In HFS-style, an absolute path is a path that contains colons but doesn't begin with one (and the disk name must be specified as the first path component, even if it's the boot path); POSIX-style identifies an absolute path as one beginning with a slash (and the disk name is omitted, so a path to a non-boot volume must explicitly wend its way through to the volume's mount point, usually in /Volumes). Fortunately, you don't need to deal with any of that either. "... as text" converts an alias or file to an HFS-style path; "POSIX path of ..." converts an HFS-style path to the equivalent POSIX-style path, and "quoted form of ..." makes Terminal happy. In the other direction, "POSIX file ..." converts a POSIX-style path to a file; "alias ..." converts a file or an HFS-style path to an alias, and everybody except Terminal is happy working with aliases Assuming list_of_pics is already a list of POSIX paths: Code:
on run {list_of_pics}
set command to "echo jhead -n%Y-%m-%d_%H-%M-%S"
repeat with aPic in list_of_pics
set command to command & " " & quoted form of aPic
end repeat
tell application "Terminal"
activate
do script command
end tell
end run
In the more usual case where list_of_pics is a list of aliases: Code:
on run {list_of_pics}
set command to "echo jhead -n%Y-%m-%d_%H-%M-%S"
repeat with aPic in list_of_pics
set command to command & " " & quoted form of POSIX path of (aPic as text)
end repeat
tell application "Terminal"
activate
do script command
end tell
end run
|
|
|
|
|
|
#7 |
|
Prospect
Join Date: Jul 2011
Posts: 9
|
Hello ganbustein,
thanks very much for your reply and your explanations. I tried to implement this scriptlet and it works, well, a bit. The situation is a bit strange... within the automator-pane everything works fine, but when I run it as a service under finder the variable list_of_pics however gets from '/test/test/test1.jpg' '/test/test/test2.jpg' '/test/test/test3.jpg' to '/test/test/test1.jpg' '/test/test/test2.jpg' '/test/test/test3.jpg' '/test/test/test1.jpg' '/test/test/test2.jpg' '/test/test/test3.jpg' Any idea why this is happening? I played around with the script-sniplet from you but did not get any other "logic" than: in automator it works (step-by-step) within the context of finder it is not working.. |
|
|
|
|
|
#8 |
|
MVP
Join Date: Apr 2008
Location: Berkeley CA USA
Posts: 1,009
|
Check the input to the "Run AppleScript" step, by adding a "View Results" step just before it. I'll bet you'll find that the list of files has already been duplicated before it even reaches your script.
A Service takes some externally-specified data and operates on it. For example, you might have specified: "Service receives selected (files or folders) in (Finder.app)" at the top of the service workflow. But for testing purposes, you probably included a "Get Selected Finder Items" step (because when you're testing, it isn't a Service yet, and doesn't have any input). The result is that your Service now gets the Finder selection (because it's a Service) and also gets the Finder selection (because you told it to). If you get the Finder selection twice, you process it twice. |
|
|
|
|
|
#9 |
|
Prospect
Join Date: Jul 2011
Posts: 9
|
Well, ganbustein I think you know it already, but you are totally right...
I am really feeling like a complete idiot... somehow I try to find excuses but, well - forget it. It is quiet logical what you are telling me but somehow I did not get it by myself. Is there any good book out there which explains such basics of automator and apple-scripting you would recommend for a newbie? Thanks a lot. Finally something of my "todo-list" which I can mark as "done". |
|
|
|
|
|
#10 |
|
MVP
Join Date: Apr 2008
Location: Berkeley CA USA
Posts: 1,009
|
Not just a book, but a whole school. The School of Hard Knocks. How do you think we know this stuff? We've all already made the same mistakes ourselves. We say "Don't step there, step here," and sound so smart, because we usually omit the rest of the sentence: "because 'there' is where I stepped and fell flat on my ... ."
For AppleScript, I can recommend "AppleScript: The Definitive Guide" by Matt Neuburg. I've never read a book on Automator, so can't help you there. |
|
|
|
![]() |
| Tags |
| automator, modify, spaces, text, variable |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|