• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: working with find command
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: working with find command


  • Subject: Re: working with find command
  • From: Christopher Stone <email@hidden>
  • Date: Tue, 18 Aug 2015 16:40:22 -0500

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

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

References: 
 >working with find command (From: Die Fledermaus <email@hidden>)

  • Prev by Date: Re: working with find command
  • Next by Date: Re: working with find command
  • Previous by thread: Re: working with find command
  • Next by thread: Requesting advice with TextEdit & Acrobat printing
  • Index(es):
    • Date
    • Thread