Search code examples
frameworksapplescriptfoundation

How can you use "use framework" Foundation " and " use scripting additions " with " info for POSIX file "?


I went around every framework, every time I try "info for POSIX file" or "info for file" I have a file error not found. For the moment, I've gone back to the "do shell script" (basename, dirname, ls) which works very well. it is very penible in an applescript script to have recourse to "do shell script"

below an example script that does not work with "use framework" Foundation "
and " info for POSIX file "

global testdir
use framework "Foundation"
use scripting additions

    set testdir to POSIX path of (choose file)

    set {name:Nm, name extension:Ex} to info for POSIX file testdir

Solution

  • info for takes an alias or file reference, such as the result from choose file. POSIX file is from the StandardAdditions Scripting Addition (Foundation is a Cocoa framework that applies more to AppleScriptObjC), and is just one of those items that doesn’t work well everywhere. In this case, it works better as a coercion:

    set {name:Nm, name extension:Ex} to info for (testdir as POSIX file)
    

    info for has also been deprecated for a while - System Events is the recommend alternative, and tends to work better with POSIX paths:

    tell application "System Events" to set {name:Nm, name extension:Ex} to disk item testdir