text
stringlengths
0
15.7k
source
stringlengths
6
112
if resType = files list and AppleScript's version > "2.4" then
lns3.scpt
return "files"
lns3.scpt
else if resType = names list then
lns3.scpt
return "names"
lns3.scpt
else if resType = POSIX names list then
lns3.scpt
return "POSIX names"
lns3.scpt
else if resType = urls array then
lns3.scpt
return "urls"
lns3.scpt
return "paths"
lns3.scpt
return resType
lns3.scpt
end stringFromRestype:
lns3.scpt
on copyWithResultItem:aFileOrPath intoFolder:folderOrPath withReplacing:replaceFlag newName:destName withReturnPath:pathFlag
lns3.scpt
if destName is missing value then set destName to theSourceURL's |lastPathComponent|()
lns3.scpt
set theResult to my copyFromURL:theSourceURL toURL:theDestURL withReplacing:replaceFlag
lns3.scpt
if theResult then return theDestURL's path() as text
lns3.scpt
end copyWithResultItem:intoFolder:withReplacing:newName:withReturnPath:
lns3.scpt
on moveWithResultItem:aFileOrPath intoFolder:folderOrPath withReplacing:replaceFlag newName:destName withReturnPath:pathFlag
lns3.scpt
set theResult to my moveFromURL:theSourceURL toURL:theDestURL withReplacing:replaceFlag
lns3.scpt
end moveWithResultItem:intoFolder:withReplacing:newName:withReturnPath:
lns3.scpt
on renameWithResultItem:aFileOrPath newName:proposedName
lns3.scpt
set theResult to my moveFromURL:theSourceURL toURL:theDestURL withReplacing:false
lns3.scpt
end renameWithResultItem:newName:
lns3.scpt
on atomicReplaceFromURL:sourceURL toURL:destinationURL
lns3.scpt
set {tempURLDir, theError} to theFileManager's URLForDirectory:99 inDomain:1 appropriateForURL:destinationURL create:true |error|:(reference) -- 1 = NSUserDomainMask, 99 = NSItemReplacementDirectory
lns3.scpt
if tempURLDir is missing value then error (theError's |localizedDescription|() as text) number (theError's code() as integer)
lns3.scpt
set tempDestURL to tempURLDir's URLByAppendingPathComponent:(destinationURL's lastPathComponent())
lns3.scpt
set {theResult, theError} to (theFileManager's copyItemAtURL:sourceURL toURL:tempDestURL |error|:(reference))
lns3.scpt
if not theResult as boolean then
lns3.scpt
theFileManager's removeItemAtURL:tempURLDir |error|:(missing value)
lns3.scpt
set {theResult, theError} to theFileManager's replaceItemAtURL:destinationURL withItemAtURL:tempDestURL backupItemName:(missing value) options:1 resultingItemURL:(missing value) |error|:(reference) -- 1 = NSFileManagerItemReplacementUsingNewMetadataOnly
lns3.scpt
if not theResult as boolean then error (theError's |localizedDescription|() as text) number (theError's code() as integer)
lns3.scpt
end atomicReplaceFromURL:toURL:
lns3.scpt
on sortByNameOrExtensionFilesOrPaths:listOfFilesOrPaths lowToHigh:ascendFlag sortingStyle:sortStyle resultType:resType byExtension:extensionFlag
lns3.scpt
if ((NSArray's arrayWithArray:listOfFilesOrPaths)'s firstObject()'s isKindOfClass:(|NSURL|)) as boolean then
lns3.scpt
set theResults to NSMutableArray's arrayWithArray:listOfFilesOrPaths
lns3.scpt
(theResults's addObject:(my makeURLFromFileOrPath:aFile))
lns3.scpt
if extensionFlag then
lns3.scpt
set sortDesc2 to NSSortDescriptor's sortDescriptorWithKey:"pathExtension" ascending:ascendFlag selector:sortStyle
lns3.scpt
set sortDesc to NSSortDescriptor's sortDescriptorWithKey:"lastPathComponent.stringByDeletingPathExtension" ascending:ascendFlag selector:sortStyle
lns3.scpt
theResults's sortUsingDescriptors:{sortDesc2, sortDesc}
lns3.scpt
set sortDesc to NSSortDescriptor's sortDescriptorWithKey:"lastPathComponent" ascending:ascendFlag selector:sortStyle
lns3.scpt
theResults's sortUsingDescriptors:{sortDesc}
lns3.scpt
return my convertURLs:theResults resultType:resType
lns3.scpt
end sortByNameOrExtensionFilesOrPaths:lowToHigh:sortingStyle:resultType:byExtension:
lns3.scpt
on tags of theFileOrPathInput
lns3.scpt
return my returnTagsFor:theFileOrPathInput
lns3.scpt
end tags of
lns3.scpt
on set tags of tagList to theFileOrPathInput
lns3.scpt
return my setTags:tagList forItem:theFileOrPathInput
lns3.scpt
end set tags of
lns3.scpt
on remove tags from theFileOrPathInput
lns3.scpt
return my setTags:{} forItem:theFileOrPathInput
lns3.scpt
end remove tags from
lns3.scpt
on add tags tagList to theFileOrPathInput
lns3.scpt
return my addTags:tagList forItem:theFileOrPathInput
lns3.scpt
end add tags
lns3.scpt
on returnTagsFor:theFileOrPathInput
lns3.scpt
set thisURL to my makeURLFromFileOrPath:theFileOrPathInput -- make URL
lns3.scpt
set {theResult, theTags, theError} to thisURL's getResourceValue:(reference) forKey:NSURLTagNamesKey |error|:(reference)
lns3.scpt
if theResult as boolean is false then error (theError's |localizedDescription|() as text)
lns3.scpt
if theTags = missing value then return {} -- because when there are none, it returns missing value
lns3.scpt
return theTags as list
lns3.scpt
end returnTagsFor:
lns3.scpt
on setTags:tagList forItem:theFileOrPathInput
lns3.scpt
set {theResult, theError} to thisURL's setResourceValue:tagList forKey:NSURLTagNamesKey |error|:(reference)
lns3.scpt
end setTags:forItem:
lns3.scpt
on addTags:tagList forItem:theFileOrPathInput
lns3.scpt
if theTags ≠ missing value then -- make list of old and new tags
lns3.scpt
set tagList to (theTags as list) & tagList
lns3.scpt
set tagList to (current application's NSOrderedSet's orderedSetWithArray:tagList)'s |allObjects|() -- delete any duplicates
lns3.scpt
set {theResult, theError} to thisURL's setResourceValue:tagList forKey:(NSURLTagNamesKey) |error|:(reference)
lns3.scpt
end addTags:forItem:
lns3.scpt
on date info for theFileOrPathInput returning dictionary dictFlag : false
lns3.scpt
set {theResult, theError} to thisURL's resourceValuesForKeys:{NSURLContentModificationDateKey, NSURLCreationDateKey, NSURLAddedToDirectoryDateKey, NSURLContentAccessDateKey} |error|:(reference)
lns3.scpt
if theResult is missing value then error (theError's |localizedDescription|() as text)
lns3.scpt
set theResult to theResult's objectsForKeys:{NSURLCreationDateKey, NSURLContentModificationDateKey, NSURLAddedToDirectoryDateKey, NSURLContentAccessDateKey} notFoundMarker:(current application's NSNull's null())
lns3.scpt
set theResult to current application's NSDictionary's dictionaryWithObjects:theResult forKeys:{"creation_date", "modification_date", "added_date", "last_access_date"}
lns3.scpt
if dictFlag then return theResult
lns3.scpt
end date info for
lns3.scpt
on change value for theFileOrPathInput to theDate property name dateProperty : modification property
lns3.scpt
if dateProperty = modification property then
lns3.scpt
set {theResult, theError} to thisURL's setResourceValue:theDate forKey:NSURLContentModificationDateKey |error|:(reference)
lns3.scpt
else if dateProperty = last access property then
lns3.scpt
set {theResult, theError} to thisURL's setResourceValue:theDate forKey:NSURLContentAccessDateKey |error|:(reference)
lns3.scpt
else if dateProperty = created property then
lns3.scpt
set {theResult, theError} to thisURL's setResourceValue:theDate forKey:NSURLCreationDateKey |error|:(reference)
lns3.scpt
else if dateProperty = added property then
lns3.scpt
set {theResult, theError} to thisURL's setResourceValue:theDate forKey:NSURLAddedToDirectoryDateKey |error|:(reference)
lns3.scpt
error "Invalid date property parameter"
lns3.scpt
if theResult is false then error (theError's |localizedDescription|() as text)
lns3.scpt
end change value for
lns3.scpt
use AppleScript version "2.4" -- 10.10 or later
lns3.scpt
on perform search predicate string predString in folders filesAliasesURLsOrPosixPaths : missing value just in fileAliasURLOrPosixPath : missing value in scopes listOfScopes : missing value search arguments argList : {} attributes to include attList : missing value converting dates datesFlag : false names only namesFlag : false
lns3.scpt
if filesAliasesURLsOrPosixPaths is not missing value then
lns3.scpt
my searchFolders:filesAliasesURLsOrPosixPaths searchString:predString searchArgs:argList forAttributes:attList convertDates:datesFlag
lns3.scpt
else if fileAliasURLOrPosixPath is not missing value then
lns3.scpt
my searchOnlyIn:fileAliasURLOrPosixPath searchString:predString searchArgs:argList forAttributes:attList convertDates:datesFlag namesOnly:namesFlag
lns3.scpt
else if listOfScopes is not missing value then
lns3.scpt
my searchIn:listOfScopes searchString:predString searchArgs:argList forAttributes:attList convertDates:datesFlag
lns3.scpt
error "You must specify one of the 'in folders', 'just in' or 'in scope' parameters." from me
lns3.scpt