On Aug 18, 2015, at 15:51, Die Fledermaus < email@hidden> wrote: I am trying to get this to work
set mypath to "/Users/ifbell/Desktop/processedvid/source.mp4"
set status1 to do shell script "[ -f " & quoted form of mypath & " ] && echo yes1 || echo no1" as text
______________________________________________________________________
Hello Die,
That's very unnecessarily circuitous, but here's a working example:
------------------------------------------------------ set myPath to "/Users/chris/Downloads/test me.txt"
set shCMD to text 2 thru -1 of (" FILE=" & quoted form of myPath & "; [ -f \"$FILE\" ] && echo 'Yes_01' || echo 'No_01'; ")
set fileExists to do shell script shCMD ------------------------------------------------------
I only get the output no1 no matter whether the file exists or not. Is this just a fools errand to make this work?
Not at all. You just need to improve your understanding of the mysteries of AppleScript. :)
I am unable to get this command to work if exists POSIX file mypath as alias then
------------------------------------------------------ set myPath to "/Users/chris/Downloads/test me.txt"
set myAlias to alias POSIX file myPath
# OR
set myAlias to (POSIX file myPath) as alias ------------------------------------------------------
These WON'T coerce to alias IF the file does NOT exist, so your test is already done for you.
Now then as you may be aware exists does not live outside of an app in this context.
------------------------------------------------------ # WORKS: ------------------------------------------------------
set myPath to "/Users/chris/Downloads/test me.txt"
tell application "System Events" exists disk item myPath end tell
------------------------------------------------------ # WORKS: ------------------------------------------------------
set myPath to "/Users/chris/Downloads/test me.txt" set myPosixFile to POSIX file myPath
tell application "Finder" exists myPosixFile end tell
------------------------------------------------------ # THIS *DOESN'T* WORK: ------------------------------------------------------
set myPath to "/Users/chris/Downloads/test me.txt"
tell application "Finder" exists POSIX file myPosixFile end tell
------------------------------------------------------
If you were trying this last one in the Finder you now have your answer.
While Posix Files work in certain contexts in the Finder there are some gotchas.
------------------------------------------------------ # THIS *DOES* WORK: ------------------------------------------------------
tell application "Finder" exists POSIX file "/Users/chris/Downloads/test me.txt" end tell
------------------------------------------------------
When working in the Finder I prefer to always use aliases or HFS paths to ensure that I don't get bitten by this sort of thing.
-- Best Regards, Chris
|