Hi. Since I tried to adapt my soft from sierra to high Sierra, I have a lot of problem with finder.
For example duplicate file or get size of a file.
Tell application « finder »
Set ab to size of file XY as alias
End tell
Get error. File not found
Any idea ?
Thanks
If you’re writing an Xcode-based app, you should be trying to use Foundation rather than the Finder.
Hi Shane.
Yes, all my application is in Xcode but totally AppleScript inside
I have near 3000 lines of code for all fonctions vs Illustrator or photoshop
Pilot those soft works fine in every OS System.
Where can I find like dictionnary function of « Foundation » ?
Thanks. Chris
When I say Foundation, I mean using the NSFileManager, NSWorkspace and NSURL classes of the Foundation framework via AppleScriptObjC. These let you do most things you would otherwise do in the Finder.
HI Shane. Thanks a lot for your help
I look at apple developer about those function and try to make work with it
Here is an example (i want to try to have the size of the file in hard disk)
tell application "Adobe Illustrator"
set pathfile to POSIX path of (file path of current document as text)
end tell
tell application "Finder"
set infoFile to current application's componentsToDisplayForPath:pathfile
display dialog infoFile
end tell
(*
- componentsToDisplayForPath:
Returns an array of strings representing the user-visible components of a given path.
*)
but got an error
tell application "Script Editor"
attributesOfItemAtPath_("/Users/cporte/Desktop/Cartouche_Implementation.ai")
--> error number -1708
So what is the syntax for those function ? What is the difference beetwwen (+) or (-) or nothing in front of those function.
Sorry if it seems ridiculous, but i’m loose
One more thanks for help you give to every one
Chris
It’s not something I can answer in a single message – you need to have some understanding of AppleScriptObjC. The only book I know of on the subject is the one I wrote – I suggest that, but understand I’m obviously biased.
Hi. i already buy them a long time ago
May be i should read those book again
Hope i will understand, otherwise, i will be oblige to stop my soft and it’s a real shame.
Using it, i can win nearly one hour per day to do my graphic job
Thanks in every case
Chris
Chapters 14 and 15 are most relevant to files and file management.
To answer your original question, you can use something like:
set theURL to current application's NSURL's fileURLWithPath:posixPath
set {theResult, fileSize} to theURL's getResourceValue:(reference) forKey:(current application's NSURLFileSizeKey) |error|:(missing value)
set fileSize to fileSize as integer
I’m reading the chapter 16 of "AppleScriptObjC Explored 5. It’s the last on a bought
So i will read carrefuly an try to understand the logical of the declaration for function
Regards. Thanks for the last example. ( i was looking with FileManager also)
I was referring to chapters in the book ‘Everyday AppleScriptObjC’, which is not Xcode-specific.
Ok. I just see it on your website. So i will buy it now. Thanks