Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.sys.mac.system > #90419

Re: Applescript Q: file specifications

From Paul Sture <nospam@sture.ch>
Newsgroups comp.sys.mac.system
Subject Re: Applescript Q: file specifications
Date 2016-03-27 10:53 +0200
Organization PostgreSQL and SQLite
Message-ID <6ljksc-ssh.ln1@news.chingola.ch> (permalink)
References <56f7758c$0$9287$c3e8da3$5d8fb80f@news.astraweb.com>

Show all headers | View raw


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.

Back to comp.sys.mac.system | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

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

csiph-web