Since offending object
is singular I’ve always operated on the idea that an AppleEvent should stop at the first error.
My solution for this kind of conflict is to use synonyms in the terminology dictionary.
In this case, I would use something like file is at
as the verb and exists file
as the synonym.
Thus, the user only has to remember the former that will be replaced during compilation by the latter.
Hmmm… my preference would be to process all, and return two lists as errors.
A list is a single object.
(in my case these errors only crop up when processing a large list of files and during the processing something happens to one of the files before the script gets to it. (It’s moved, opened, renamed or deleted by a user).
This is odd, turns out the command doesn’t want to return a boolean or text. When I run this the variable “testingFolder” is never set. But, the folder is created.
use scripting additions
use script "FileManagerLib"
set testingLocation to path to documents folder as alias
set testingFolder to create folder at testingLocation ¬
use name "TestingA"
So now I’m on a mission to remove all finder calls from these scripts. Here’s what I have left:
tell application "Finder" to set dailygridfolder to (folder 1 of dailygridfolder whose name contains gridFolderName) as alias
tell application "Finder" to set liveFiles to (files of liveMasterLogsFolder whose name contains ".TXT") as alias list
tell application "Finder" to set gridFiles to (item 1 of daysStuffedFolder whose name contains gridFileSlug) as alias
tell application "Finder" to set the file type of movedFiles to "OURT"
tell application "Finder" to set folderName to the name of folder dailyDocsFolder
tell application "Finder" to set homeFolder to the container of homeFolder as alias
You may want to make your own library, but this should get you started:
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions
use script "FileManagerLib" version "2.0"
on returnFiles:fileFlag andFolders:folderFlag inFolder:theFolder containing:searchString itemIndex:theIndex -- index of 0 means all
set theItems to contents of theFolder result type files list include files fileFlag include folders folderFlag
set theItems to current application's NSArray's arrayWithArray:theItems
set thePred to current application's NSPredicate's predicateWithFormat:"lastPathComponent CONTAINS[c] %@" argumentArray:{searchString}
if theIndex = 0 then
return (theItems's filteredArrayUsingPredicate:thePred) as list
else
return item theIndex of ((theItems's filteredArrayUsingPredicate:thePred) as list)
end if
end returnFiles:andFolders:inFolder:containing:itemIndex:
on setFileType:fourLetterCode forPosixPath:posixPath
set theCode to current application's NSHFSTypeCodeFromFileType("'" & fourLetterCode & "'")
set fileManager to current application's NSFileManager's defaultManager()
set {theResult, theError} to fileManager's setAttributes:{NSFileHFSTypeCode:theCode} ofItemAtPath:posixPath |error|:(reference)
if not theResult as boolean then error theError's localizedDescription() as text
end setFileType:forPosixPath:
See FileManagerLib’s parse item
command.
Don’t see that command in that library. Maybe you mean a different lib? (This is where searching all library dictionaries would be nice).
It looks like my emails aren’t getting through to you. I sent you a newer version.