---------------------------------------------------------------------------------
--» exTant()
---------------------------------------------------------------------------------
-- Task: Determine whether a file or folder exists.
-- dMod: 2015/06/30 07:12
---------------------------------------------------------------------------------
on exTant(_path) # Takes an HFS, Posix, or ~/Posix path as input.
try
if _path is "~" or _path is "~/" then
set _path to (POSIX path of (path to home folder as text))
else if _path starts with "~/" then
set _path to (POSIX path of (path to home folder as text)) & text 3 thru -1 of _path
end if
if _path starts with "/" then
alias POSIX file _path
else
alias _path
end if
return true
on error
return false
end try
end exTant
---------------------------------------------------------------------------------
[ Edited to repair the glaring bug Shane pointed out and to cover instances of home-notation without a following path: ‘~’ & ‘~/’ -ccs ]
Used the script from DJ for Excel 2011 and because the new Mac Office version have problems with running applescript with the VBA MacScript function I can’t use it in this version. But they fixed VBA Dir (no filename limit of 32 characters anymore) so I can use that in the Office beta.
tell application "Finder"
set finderRef to first item of (path to documents folder)
end tell
--> folder "Access_Aliases" of folder "Documents" of folder "chris" of folder "Users" of startup disk of application "Finder"
set myPath to finderRef as text
--> "Ryoko:Users:chris:Documents:Access_Aliases:"
Yes, it appears that :
(1) the script extracts item 1 of what, as far as I know, is not a list
(2) it convert the alias which is known by quite every applications into a reference which quite only the Finder is aware of.
Yvan KOENIG (VALLAURIS, France) mercredi 1 juillet 2015 18:33:13
set docsFolder to path to documents folder
tell application "Finder"
set finderRef to first item of docsFolder
end tell
tell application "BBEdit"
set myPath to finderRef as text
end tell
EVENT LOG:
tell current application
path to documents folder
--> alias "Ryoko:Users:chris:Documents:"
end tell
tell application "Finder"
get item 1 of alias "Ryoko:Users:chris:Documents:"
--> folder "Access_Aliases" of folder "Documents" of folder "chris" of folder "Users" of startup disk
get folder "Access_Aliases" of folder "Documents" of folder "chris" of folder "Users" of startup disk
--> "Ryoko:Users:chris:Documents:Access_Aliases:"
end tell
Result:
"Ryoko:Users:chris:Documents:Access_Aliases:"
This is on OSX 10.9.5.
Very interesting that the Finder-Ref coerced to Text within a BBEdit Tell-Block reaches back to the Finder.
And if the Finder can do this then why not System Events?
It is unsurprising that the Finder can resolve an alias, so I’ve separated that out in the script.
You can refer to items by their index in the Finder, so that is of no surprise:
tell application "Finder"
set iLoc to (insertion location)
set item_01 to item 1 of iLoc
set item_02 to item 2 of iLoc
set item_20 to item 20 of iLoc
set item_40 to item 40 of iLoc
end tell
So the two things I see as “funny” or of especial interest are:
A) Where the coercion to text takes place (Finder).
B) And I think it’s very surprising for you to end up with a .DS_Store file as a result.
I thought I posted this the other day, but whatever…
If you run this:
tell application "Finder"
set finderRef to first item of docsFolder
end tell
and look at the result rather than the log, you see it ends in of application “Finder”. So coercing it inside a BBEdit tell block is a bit like a tell within a tell.
FWIW, I get the same here – it depends on whether you have hidden files visible or not.
I KNOW that finderRef is a Finder Reference ” I set it to one and named the variable appropriately for a reason.
The interesting thing is that coercing it to text OUTSIDE of a Finder-Tell works ” whether in another application Tell-Block or in vanilla AppleScript space.
If you try this with System Events it will throw an error.
If try it with other Application-References it will throw an error.
The fact that this coercion creates its own invisible tell-block is anomalous.
Ah, that makes sense. Do you run your system that way normally? If so ” just out of curiosity ” do you have any special reasons?
I (almost) never turn invisibles on in the Finder. If I want to see them I fire up ForkLift or Path Finder and make them visible.
AppleScript is routing the event to the correct application? That seems to fly in the face of the convention of not using osax-calls within an application tell-block.