Re: Split PDF and reduce file size - finished script in PDFTK
Re: Split PDF and reduce file size - finished script in PDFTK
- Subject: Re: Split PDF and reduce file size - finished script in PDFTK
- From: Adam Wuellner <email@hidden>
- Date: Fri, 12 Aug 2005 12:09:28 -0500
On 8/12/05, Gary (Lists) <email@hidden> wrote:
> "Paul Berkowitz" wrote:
>
> > On 8/11/05 11:36 PM, "Ian Cook" <email@hidden> wrote:
> >
> >> -When running from Applescript you have to use the POSIX path on the shell
> >> command
> >
> > If there are spaces somewhere in the file name and/or file paths of input or
> > output, would you not need 'quoted form'? Maybe it's safest to include it
> > for general use?
>
> Since you mention this, a couple of questions I've formed yesterday...
>
> Some shell tools take a posix path, and some take a quoted form of
> something. It's a bit maddening trying to figure it out, since 'man' pages
> aren't dictionaries.
>
> But, to the degree that I've already figured out what form to provide, I
> also have the problem of spaces.
>
> 1. Do all spaces in posix paths need "\\ " in them?
>
> 'quoted form of' doesn't do that, but it is then sometimes the cause of
> failure.
>
> 2. What's the best way to "encode" those spaces if 'quoted form' doesn't do
> it?
>
> Right now, for the shell tools that require a delimited quoted form I'm
> using Smile's 'change' for myself and TIDs for vanilla applescript.
>
> I'm confuse-ed about this and would appreciate any clarification on when
> 'posix path' vs. 'quoted form' (maybe of the p.p.) vs. space-delimted (maybe
> quoted form of)...?
Gary,
This is my understanding, and I'd be grateful to hear any
corrections.
The shell only understands POSIX paths. These are POSIX paths:
/Users/akw/Desktop/Picture 1.pdf
~/.profile
/Volumes/scratch/temp/untitled.graffle
Because the shell expects a certain syntax, and provides a
language with keywords and grammatical rules, you must quote or
escape some characters when they occur in paths. Spaces are the
obvious example. I've also seen filenames with possessive nouns
in them, e.g. Mom's Recipes.doc. That apostrophe requires
quoting or escaping if it is to be passed to a command in the
shell.
Quoting is a way of escaping a string of characters. Escaping is
a way of forcing the shell to interpret a single character
literally in its location within a string. Which method you
choose to employ is a matter of preference, convenience, or
accident - whichever it is, the effect is the same from the
shell's perspective.
"Mom's Recipes.doc" == Mom\'s\ Recipes.doc
Note that quoting can be achieved with either a pair of double
quotes or a pair of single quotes. Single quotes force all
contained characters to be interpreted literally. Note that a
single quote cannot occur within a single quoted string, even if
it preceded by the backslash (escape) character - this is because
the backslash character is itself treated literally within the
context of a single quoted string. Double quotes allow for some
forms of interpolation within the quoted string, as well as the
use of the escape character to embed a double quote within a
double quoted string.
Quoting can also be done on path segments:
/Volumes/'some name with spaces'/more/path/segments/file.txt
But that may not end the story. The shell also subjects command
lines to expansion. There are several types of expansion that
occur in sequence, but the most relevant to this discussion are
tilde expansion and pathname expansion. Tilde expansion is the
translation of the tilde character to the path of the user's home
folder. ~/ becomes /Users/akw/ on my machine. In the case of
users with network home folders, the expanded path is much
longer. I am not certain that tilde expansion works within the
context of do shell script. Pathname expansion is, I believe,
the same thing as 'globbing', and occurs if a path contains *, ?,
or [. Each of those characters signals to the shell that the
pathname is in fact a pattern that may match any number of actual
paths.
Now, there is the matter of making sure that your carefully
quoted/escaped string makes it from your AppleScript to the shell
intact. AppleScript, too, will apply its own string
interpolation mechanisms to whatever string parameter you supply
to 'do shell script'. There is not as much going on as there is
at the shell, but it is important to be aware of it nonetheless.
I find the following resources most helpful when things get
confusing:
Technical Note TN2065 - do shell script in AppleScript
http://developer.apple.com/technotes/tn2002/tn2065.html
Pertinent answered Q's:
Q: My command doesn't work right when a parameter has spaces or
certain punctuation — parentheses, $, *, etc.
Q: I need to put double quotes and backslashes in my shell
command, but AppleScript gives me a syntax error when I try.
Q: I have an AppleScript file or alias object; how do I pass it
to a shell command?
Q: POSIX path doesn't work right if the file has certain
characters in its name — spaces, parentheses, $, *, etc.
GNU Bash Reference Manual
http://www.network-theory.co.uk/docs/bashref/index.html
(In particular, section 3.1.2 Quoting, and section 3.5 Shell
Expansion)
BTW, I've found the experience of reading man pages much
friendlier after installing manServer. This is the man page for
manServer, as displayed by manServer:
http://www.squarebox.co.uk/users/rolf/download/manServer.shtml
the download link is near the bottom of that page, if you think
it would be useful to you.
Sorry for the long post. There is a lot to grok on this subject,
and I thought I'd take the liberty of trying to articulate as
much as I understand about it, as much for my own benefit as for
anyone elses.
Hope it is of some help,
Adam
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden