Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.sys.mac.system > #90413 > unrolled thread
| Started by | JF Mezei <jfmezei.spamnot@vaxination.ca> |
|---|---|
| First post | 2016-03-27 01:54 -0400 |
| Last post | 2016-03-27 16:53 +0000 |
| Articles | 13 — 4 participants |
Back to article view | Back to comp.sys.mac.system
Applescript Q: file specifications JF Mezei <jfmezei.spamnot@vaxination.ca> - 2016-03-27 01:54 -0400
Re: Applescript Q: file specifications dempson@actrix.gen.nz (David Empson) - 2016-03-27 21:36 +1300
Re: Applescript Q: file specifications JF Mezei <jfmezei.spamnot@vaxination.ca> - 2016-03-27 15:10 -0400
Re: Applescript Q: file specifications Jolly Roger <jollyroger@pobox.com> - 2016-03-27 19:25 +0000
Re: Applescript Q: file specifications dempson@actrix.gen.nz (David Empson) - 2016-03-28 12:35 +1300
Re: Applescript Q: file specifications JF Mezei <jfmezei.spamnot@vaxination.ca> - 2016-03-28 02:55 -0400
Re: Applescript Q: file specifications Jolly Roger <jollyroger@pobox.com> - 2016-03-28 15:47 +0000
Re: Applescript Q: file specifications JF Mezei <jfmezei.spamnot@vaxination.ca> - 2016-03-28 15:20 -0400
Re: Applescript Q: file specifications Jolly Roger <jollyroger@pobox.com> - 2016-03-28 20:03 +0000
Re: Applescript Q: file specifications JF Mezei <jfmezei.spamnot@vaxination.ca> - 2016-03-28 17:08 -0400
Re: Applescript Q: file specifications Jolly Roger <jollyroger@pobox.com> - 2016-03-28 21:15 +0000
Re: Applescript Q: file specifications Paul Sture <nospam@sture.ch> - 2016-03-27 10:53 +0200
Re: Applescript Q: file specifications Jolly Roger <jollyroger@pobox.com> - 2016-03-27 16:53 +0000
| From | JF Mezei <jfmezei.spamnot@vaxination.ca> |
|---|---|
| Date | 2016-03-27 01:54 -0400 |
| Subject | Applescript Q: file specifications |
| Message-ID | <56f7758c$0$9287$c3e8da3$5d8fb80f@news.astraweb.com> |
Question (trying to understand the file system). > set outfile to open for access "/users/jfmezei/Pictures/iphoto_convert.txt" with write permission works > set outfile to open for access "~/Pictures/iphoto_convert.txt" with write permission fails. is the interpretation of "~" something that only Bash understands and replaces it with your home directory spec ? I was under the impression that the "~" was something which was pervasive to the file system with lower level conversion to your home directory. I spent much time debugging the statement with errors such as not having network file access etc until i tries it with the /users/jfmezei instead of ~. Also, almost all the examples I have found seem to insist on building the file specification seperately by assembling a path and adding the file name. Is there a reason for this ?
[toc] | [next] | [standalone]
| From | dempson@actrix.gen.nz (David Empson) |
|---|---|
| Date | 2016-03-27 21:36 +1300 |
| Message-ID | <1mksh01.1t27xubng8j2uN%dempson@actrix.gen.nz> |
| In reply to | #90413 |
JF Mezei <jfmezei.spamnot@vaxination.ca> wrote: > Question (trying to understand the file system). > > > > set outfile to open for access > > "/users/jfmezei/Pictures/iphoto_convert.txt" with write permission > > works > > > set outfile to open for access "~/Pictures/iphoto_convert.txt" with > > write permission > > fails. > > > is the interpretation of "~" something that only Bash understands and > replaces it with your home directory spec ? Yes, and a few other places (such as Finder) which specifically recognise it. man bash, find the section titled "Tilde expansion". > I was under the impression that the "~" was something which was pervasive > to the file system with lower level conversion to your home directory. Nope. I did a simple test, writing a C program to output to a file referenced by a ~ prefixed pathname and it failed, but it worked with a full path (or a relative path). > I spent much time debugging the statement with errors such as not having > network file access etc until i tries it with the /users/jfmezei instead > of ~. > > Also, almost all the examples I have found seem to insist on building > the file specification seperately by assembling a path and adding the > file name. Is there a reason for this ? Can you give a brief example? -- David Empson dempson@actrix.gen.nz
[toc] | [prev] | [next] | [standalone]
| From | JF Mezei <jfmezei.spamnot@vaxination.ca> |
|---|---|
| Date | 2016-03-27 15:10 -0400 |
| Message-ID | <56f8302a$0$14578$b1db1813$2411a48f@news.astraweb.com> |
| In reply to | #90418 |
On 2016-03-27 04:36, David Empson wrote:
> Yes, and a few other places (such as Finder) which specifically
> recognise it.
Thanks. There are a lot of difrerences between Unix and VMS in terms of
file handling and I guess this is one more I learned. I knew that
wildcard expansion on a command is done by bash. Didn't realise "~" was
bash as well.
I take it that relative specification such as ../myfile.txt are also
interpreted by bash and thus not available when accessing files outsde
of bash ?
>
> Can you give a brief example?
>
googled for applescript write text file and first example: (and almost
all examples).
set outputFile to ((("/Users/david/Desktop/") as string) &
"LaunchAgent_Alert.txt") as file specification
try
open for access outputFile with write permission
write theBody to outputFile as string
close access outputFile
end try
I can see reasons if you will translate a user's home directory and then
add further specification to the full path. But all the examples I have
seen break the directory and filename and assemble them as above even
when they are constant strings.
[toc] | [prev] | [next] | [standalone]
| From | Jolly Roger <jollyroger@pobox.com> |
|---|---|
| Date | 2016-03-27 19:25 +0000 |
| Message-ID | <dlqqdjFh1pnU1@mid.individual.net> |
| In reply to | #90426 |
On 2016-03-27, JF Mezei <jfmezei.spamnot@vaxination.ca> wrote:
>
> I take it that relative specification such as ../myfile.txt are also
> interpreted by bash and thus not available when accessing files outsde
> of bash ?
No, ../ works fine in AppleScript POSIX paths.
> googled for applescript write text file and first example: (and almost
> all examples).
>
> set outputFile to ((("/Users/david/Desktop/") as string) &
> "LaunchAgent_Alert.txt") as file specification
>
> I can see reasons if you will translate a user's home directory and then
> add further specification to the full path. But all the examples I have
> seen break the directory and filename and assemble them as above even
> when they are constant strings.
That amounts to nothing more than personal taste.
--
E-mail sent to this address may be devoured by my ravenous SPAM filter.
I often ignore posts from Google. Use a real news client instead.
JR
[toc] | [prev] | [next] | [standalone]
| From | dempson@actrix.gen.nz (David Empson) |
|---|---|
| Date | 2016-03-28 12:35 +1300 |
| Message-ID | <1mktkf3.14k3lwj1shpznkN%dempson@actrix.gen.nz> |
| In reply to | #90426 |
JF Mezei <jfmezei.spamnot@vaxination.ca> wrote:
> On 2016-03-27 04:36, David Empson wrote:
>
> > Yes, and a few other places (such as Finder) which specifically
> > recognise it.
>
> Thanks. There are a lot of difrerences between Unix and VMS in terms of
> file handling and I guess this is one more I learned. I knew that
> wildcard expansion on a command is done by bash. Didn't realise "~" was
> bash as well.
>
> I take it that relative specification such as ../myfile.txt are also
> interpreted by bash and thus not available when accessing files outsde
> of bash ?
No, "." and ".." should work everywhere. In traditional Unix file
systems, there are actual entries in the directory with those names,
which point to the current and parent directories. Equivalent mechanisms
exist in HFS+ and other file systems, and the POSIX API exposes them as
the same "." and ".." elements.
> > Can you give a brief example?
> >
>
> googled for applescript write text file and first example: (and almost
> all examples).
>
> set outputFile to ((("/Users/david/Desktop/") as string) &
> "LaunchAgent_Alert.txt") as file specification
> try
> open for access outputFile with write permission
> write theBody to outputFile as string
> close access outputFile
> end try
>
> I can see reasons if you will translate a user's home directory and then
> add further specification to the full path. But all the examples I have
> seen break the directory and filename and assemble them as above even
> when they are constant strings.
Possibly just to better separate the bits that are more likely to need
to be changed in other scripts (or for other people).
--
David Empson
dempson@actrix.gen.nz
[toc] | [prev] | [next] | [standalone]
| From | JF Mezei <jfmezei.spamnot@vaxination.ca> |
|---|---|
| Date | 2016-03-28 02:55 -0400 |
| Message-ID | <56f8d583$0$5013$b1db1813$7968482@news.astraweb.com> |
| In reply to | #90431 |
Different question: the file specificatiosn as obtained by Applescript from iPhoto look like: > /Users/jfmezei/Pictures/iPhoto Library/Masters/2012/Baie James 2012/DSC_1311.NEF Is there an easy way to escape spaces in a string to "\ " ? Once I have the information extracted from iPhoto, applescript is likely to call the shell to run exittool to add that info to the original photo file. (some of my iPhotos already have a .xmp sidecar that was vreated with Bridge/Camera Raw, so it may be more difficult to add to those files or modify them - but this is something I am still considering).
[toc] | [prev] | [next] | [standalone]
| From | Jolly Roger <jollyroger@pobox.com> |
|---|---|
| Date | 2016-03-28 15:47 +0000 |
| Message-ID | <dlt202F3omfU1@mid.individual.net> |
| In reply to | #90442 |
JF Mezei <jfmezei.spamnot@vaxination.ca> wrote: > Different question: > > the file specificatiosn as obtained by Applescript from iPhoto look like: > >> /Users/jfmezei/Pictures/iPhoto Library/Masters/2012/Baie James 2012/DSC_1311.NEF > > Is there an easy way to escape spaces in a string to "\ " ? > > Once I have the information extracted from iPhoto, applescript is likely > to call the shell to run exittool to add that info to the original photo > file. (some of my iPhotos already have a .xmp sidecar that was vreated > with Bridge/Camera Raw, so it may be more difficult to add to those > files or modify them - but this is something I am still considering). No need to mess with space escapes. Just quote the string like so: set quotedString to the quoted form of filePath -- E-mail sent to this address may be devoured by my ravenous SPAM filter. I often ignore posts from Google. Use a real news client instead. JR
[toc] | [prev] | [next] | [standalone]
| From | JF Mezei <jfmezei.spamnot@vaxination.ca> |
|---|---|
| Date | 2016-03-28 15:20 -0400 |
| Message-ID | <56f983f0$0$16692$c3e8da3$76a7c58f@news.astraweb.com> |
| In reply to | #90445 |
On 2016-03-28 11:47, Jolly Roger wrote: > set quotedString to the quoted form of filePath set quotedfile to the quoted form of aPhoto's original path write "original: " & quotedfile & return to outfile It doesn't like the "quoted form" in first line above. iPhoto got an error: Can’t make quoted form of original path of photo id 4.294973456E+9 into type reference.
[toc] | [prev] | [next] | [standalone]
| From | Jolly Roger <jollyroger@pobox.com> |
|---|---|
| Date | 2016-03-28 20:03 +0000 |
| Message-ID | <dlth13F6q94U3@mid.individual.net> |
| In reply to | #90451 |
On 2016-03-28, JF Mezei <jfmezei.spamnot@vaxination.ca> wrote: > On 2016-03-28 11:47, Jolly Roger wrote: >> set quotedString to the quoted form of filePath > > set quotedfile to the quoted form of aPhoto's original path > write "original: " & quotedfile & return to outfile That's not what I wrote above. Notably, "aPhoto's original path" isn't necessarily a string, depending on the context. > It doesn't like the "quoted form" in first line above. > > iPhoto got an error: Can’t make quoted form of original path of photo id > 4.294973456E+9 into type reference. No, what it doesn't like is the fact that "aPhoto's original path" is resolving into an object reference: original path of photo id 22 > 4.294973456E+9. Coerce it to a string before you send it to "the quoted form of" to fix the problem: set quotedfile to the quoted form of (aPhoto's original path as text) You may get away with: set quotedfile to the quoted form of (aPhoto's original path) -- E-mail sent to this address may be devoured by my ravenous SPAM filter. I often ignore posts from Google. Use a real news client instead. JR
[toc] | [prev] | [next] | [standalone]
| From | JF Mezei <jfmezei.spamnot@vaxination.ca> |
|---|---|
| Date | 2016-03-28 17:08 -0400 |
| Message-ID | <56f99d53$0$62778$c3e8da3$dbd57e7@news.astraweb.com> |
| In reply to | #90454 |
On 2016-03-28 16:03, Jolly Roger wrote: > set quotedfile to the quoted form of (aPhoto's original path as text) This worked. So how come I am able to write "original: " & aPhoto's original path & return to outfile which seems happy to handle "original path" as a string, but can't do the "quoted form" of aPhoto's original path without it trying to quote a binary object (the phone as a whole). BTW, all it does is add a single quote at start and end of string, something that would be easier done as write "original: '" & aPhoto's original path & "'" & return to outfile or does this "quoted form" grant the string special powers and different handling because it is treated as a quoted string ? Or does it just merely add the ' characters fore and aft of the string and still considers it a string ?
[toc] | [prev] | [next] | [standalone]
| From | Jolly Roger <jollyroger@pobox.com> |
|---|---|
| Date | 2016-03-28 21:15 +0000 |
| Message-ID | <dltl87F8ir9U1@mid.individual.net> |
| In reply to | #90455 |
On 2016-03-28, JF Mezei <jfmezei.spamnot@vaxination.ca> wrote: > On 2016-03-28 16:03, Jolly Roger wrote: >> set quotedfile to the quoted form of (aPhoto's original path as text) > > This worked. > > So how come I am able to > > write "original: " & aPhoto's original path & return to outfile > > which seems happy to handle "original path" as a string, but can't do > the "quoted form" of aPhoto's original path without it trying to quote a > binary object (the phone as a whole). Because it's not resolving to a string in that context, but an object reference instead. Sometimes variables need to be coerced - in any language. > BTW, all it does is add a single quote at start and end of string, > something that would be easier done as > > write "original: '" & aPhoto's original path & "'" & return to outfile That's subjective and debatable. I consider typing "the quoted form of" to be both easier and faster in most cases. > or does this "quoted form" grant the string special powers and different > handling because it is treated as a quoted string ? Or does it just > merely add the ' characters fore and aft of the string and still > considers it a string ? set someString to "this is a string" log class of someString set anotherString to the quoted form of someString log class of anotherString -- E-mail sent to this address may be devoured by my ravenous SPAM filter. I often ignore posts from Google. Use a real news client instead. JR
[toc] | [prev] | [next] | [standalone]
| From | Paul Sture <nospam@sture.ch> |
|---|---|
| Date | 2016-03-27 10:53 +0200 |
| Message-ID | <6ljksc-ssh.ln1@news.chingola.ch> |
| In reply to | #90413 |
On 2016-03-27, JF Mezei <jfmezei.spamnot@vaxination.ca> wrote: > > Question (trying to understand the file system). > > >> set outfile to open for access "/users/jfmezei/Pictures/iphoto_convert.txt" with write permission > > works > >> set outfile to open for access "~/Pictures/iphoto_convert.txt" with write permission > > fails. > > > is the interpretation of "~" something that only Bash understands and > replaces it with your home directory spec ? I was under the impression > that the "~" was something which was pervasive to the file system with > lower level conversion to your home directory. Yes, the "~" is indeed interpreted by bash (and various other shells). Try the following, where quoting the filename disables bash interpretation. touch ~/foo.txt cd ~/Downloads # assuming you have one of these :-) ls ~/foo.txt ls '~/foo.txt' ls: ~/1.txt: No such file or directory ls "~/foo.txt" ls: ~/foo.txt" No such file or directory You will see this behaviour from compiled languages (e.g. C, Objective-C) and scripting languages like AppleScript and Python. > I spent much time debugging the statement with errors such as not having > network file access etc until i tries it with the /users/jfmezei instead > of ~. > > Also, almost all the examples I have found seem to insist on building > the file specification seperately by assembling a path and adding the > file name. Is there a reason for this ? Most compiled or scripting languages will have a library function to return your home directory, and there's often a function which will join a filename to a path, ensuring that the separator between the two is present and correct (i.e. not duplicated as in /Users/paul//foo.txt) -- There are two hard things in computer science: cache invalidation, naming, and off-by-one errors.
[toc] | [prev] | [next] | [standalone]
| From | Jolly Roger <jollyroger@pobox.com> |
|---|---|
| Date | 2016-03-27 16:53 +0000 |
| Message-ID | <dlqhfuFef9rU2@mid.individual.net> |
| In reply to | #90413 |
On 2016-03-27, JF Mezei <jfmezei.spamnot@vaxination.ca> wrote:
>
> Question (trying to understand the file system).
>
> set outfile to open for access "/users/jfmezei/Pictures/iphoto_convert.txt" with write permission
>
> works
>
> set outfile to open for access "~/Pictures/iphoto_convert.txt" with write permission
>
> fails.
>
> is the interpretation of "~" something that only Bash understands and
> replaces it with your home directory spec ? I was under the impression
> that the "~" was something which was pervasive to the file system with
> lower level conversion to your home directory.
[cross posted to alt.comp.lang.applescript]
As others have said, shells typically do that for you; but not all tools
or interfaces do it automatically, including AppleScript. It is easy to
do it yourself in AppleScript though:
-- begin script
return my ResolveRelativePath("~/Pictures/iphoto_convert.txt")
on ResolveRelativePath(relativePath)
set homePath to POSIX path of (path to home folder)
return my SearchReplace(relativePath, "~/", homePath)
end ResolveRelativePath
on SearchReplace(sourceStr, searchString, replaceString)
-- replace <searchString> with <replaceString> in <sourceStr>
set searchStr to (searchString as text)
set replaceStr to (replaceString as text)
set sourceStr to (sourceStr as text)
set saveDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to (searchString)
set theList to (every text item of sourceStr)
set AppleScript's text item delimiters to (replaceString)
set theString to theList as string
set AppleScript's text item delimiters to saveDelims
return theString
end SearchReplace
-- end script
--
E-mail sent to this address may be devoured by my ravenous SPAM filter.
I often ignore posts from Google. Use a real news client instead.
JR
[toc] | [prev] | [standalone]
Back to top | Article view | comp.sys.mac.system
csiph-web