Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You don't need to create a file before opening it for access. You can just do</p> <pre><code>set theFile to (theFolder &amp; "thefile.txt")as string set openFile to open for access theFile with write permission </code></pre> <p>Of course if the file exists it will overwrite it. You could use</p> <pre><code>set thefile to choose file name with prompt "name the output file" </code></pre> <p>'choose file name' returns a path without creating a file, and it asks the user if they want to overwrite if the file exists.</p> <p>You can also use 'return' to put a line break in like so, it makes the code a bit neater:</p> <pre><code>write fileName &amp; return to openFile </code></pre> <hr> <p>Of course if you want a simple and more elegant way of doing it, the command is where you need to be.</p> <pre><code>ls&gt;thefile.txt </code></pre> <p>In this example the '>' writes the output from the ls (list directory) command to a file. You can run this from within an applescript</p> <pre><code>set thePosixDrectory to posix path of file thedirectory of app "Finder" set theposixResults to posix path of file theresultfile of app "Finder" do shell script ("ls \"" &amp; thePosixDrectory &amp; "\"&gt;\"" &amp; theposixResults &amp; "\"")as string </code></pre> <p>the posix path stuff is to turn applescript style <code>directory:paths:to your:files</code> into unix style <code>/directory/paths/to\ your/files</code>.</p> <p>Note that the shell script that actually gets run will look like:</p> <pre><code>ls "/some/directory/path/"&gt;"/some/file/path.txt" </code></pre> <p>the quotes are there to stop spaces or other funky characters from confusing the shell script. To stop the quotes from being read as quotes in the applescript the backslash was used to "escape" them. You can also use single quotes, for more readable code thusly:</p> <p>do shell script ("ls '" &amp; thePosixDrectory &amp; "'>'" &amp; theposixResults &amp; "'")as string</p> <p>which will appear in the shell like</p> <pre><code> ls '/some/directory/path/'&gt;'/some/file/path.txt' </code></pre> <p>HTH</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload