text
stringlengths
0
15.7k
source
stringlengths
6
112
on renameItem:aFileOrPath newName:proposedName
lns3.scpt
if class of proposedName is text then set proposedName to NSString's stringWithString:proposedName
lns3.scpt
set proposedName to proposedName's stringByReplacingOccurrencesOfString:"/" withString:":"
lns3.scpt
set theDestURL to theSourceURL's |URLByDeletingLastPathComponent|()'s URLByAppendingPathComponent:proposedName
lns3.scpt
my moveFromURL:theSourceURL toURL:theDestURL withReplacing:false
lns3.scpt
end renameItem:newName:
lns3.scpt
on deleteFile:aFileOrPath
lns3.scpt
set {theResult, isDirectory, theError} to theSourceURL's getResourceValue:(reference) forKey:(NSURLIsDirectoryKey) |error|:(reference)
lns3.scpt
if not (theResult as boolean) then error (theError's |localizedDescription|() as text)
lns3.scpt
if isDirectory as boolean then
lns3.scpt
set {theResult, isPackage, theError} to theSourceURL's getResourceValue:(reference) forKey:(NSURLIsPackageKey) |error|:(reference)
lns3.scpt
if not (isPackage as boolean) then error "Item is a directory, not a file" number -10000
lns3.scpt
set theFileManager to NSFileManager's |defaultManager|()
lns3.scpt
set {theResult, theError} to theFileManager's removeItemAtURL:theSourceURL |error|:(reference)
lns3.scpt
if not (theResult as boolean) then error (theError's |localizedDescription|() as text) number (theError's code() as integer)
lns3.scpt
end deleteFile:
lns3.scpt
on deleteItem:aFileOrPath
lns3.scpt
end deleteItem:
lns3.scpt
on trashItem:aFileOrPath
lns3.scpt
set {theResult, destURL, theError} to theFileManager's trashItemAtURL:theSourceURL resultingItemURL:(reference) |error|:(reference)
lns3.scpt
return destURL's path() as text
lns3.scpt
end trashItem:
lns3.scpt
on copyItem:aFileOrPath toMake:destFileOrPath withReplacing:replaceFlag
lns3.scpt
set theDestURL to my makeURLFromFileOrPath:destFileOrPath
lns3.scpt
end copyItem:toMake:withReplacing:
lns3.scpt
on copyItem:aFileOrPath uniquelyToFolder:folderOrPath
lns3.scpt
set theDestFolderURL to my makeURLFromFileOrPath:folderOrPath
lns3.scpt
end copyItem:uniquelyToFolder:
lns3.scpt
on moveItem:aFileOrPath toMake:destFileOrPath withReplacing:replaceFlag
lns3.scpt
end moveItem:toMake:withReplacing:
lns3.scpt
on moveItem:aFileOrPath uniquelyToFolder:folderOrPath
lns3.scpt
set destNameLessExt to destName's |stringByDeletingPathExtension|()
lns3.scpt
set theExtension to theSourceURL's |pathExtension|()
lns3.scpt
set {theResult, theError} to (theFileManager's moveItemAtURL:theSourceURL toURL:theDestURL |error|:(reference))
lns3.scpt
if theResult as boolean then exit repeat
lns3.scpt
if theError's code() as integer = 516 then -- 516 = NSFileWriteFileExistsError; it already exists, so change name
lns3.scpt
if i = 0 then
lns3.scpt
set proposedName to (destNameLessExt's stringByAppendingString:copyString)'s stringByAppendingPathExtension:theExtension
lns3.scpt
set proposedName to (destNameLessExt's stringByAppendingString:(copyString & space & i))'s stringByAppendingPathExtension:theExtension
lns3.scpt
set theDestURL to theFolderURL's URLByAppendingPathComponent:proposedName
lns3.scpt
else -- an error other than file already exists, so return error
lns3.scpt
error (theError's |localizedDescription|() as text) number (theError's code() as integer)
lns3.scpt
return theDestURL's path() as text
lns3.scpt
end moveItem:uniquelyToFolder:
lns3.scpt
on createFolder:folderOrPath
lns3.scpt
set {theResult, theError} to theFileManager's createDirectoryAtURL:theFolderURL withIntermediateDirectories:true attributes:(missing value) |error|:(reference)
lns3.scpt
return theFolderURL's path() as text
lns3.scpt
end createFolder:
lns3.scpt
on createFolderNamed:proposedName inFolder:folderOrPath
lns3.scpt
if (proposedName's rangeOfString:":")'s |length|() > 0 then error "Folder names cannot include the character '/'."
lns3.scpt
set {theResult, theError} to theFileManager's createDirectoryAtURL:theDestURL withIntermediateDirectories:true attributes:(missing value) |error|:(reference)
lns3.scpt
end createFolderNamed:inFolder:
lns3.scpt
on createAlias:aFileOrPath pointingTo:originalFileOrPath
lns3.scpt
set theAliasURL to my makeURLFromFileOrPath:aFileOrPath
lns3.scpt
set originalURL to my makeURLFromFileOrPath:originalFileOrPath
lns3.scpt
set {theData, theError} to originalURL's bookmarkDataWithOptions:1024 includingResourceValuesForKeys:(missing value) relativeToURL:(missing value) |error|:(reference) -- 1024 = NSURLBookmarkCreationSuitableForBookmarkFile
lns3.scpt
if theData is missing value then error (theError's |localizedDescription|() as text) number (theError's code() as integer)
lns3.scpt
set {theResult, theError} to |NSURL|'s writeBookmarkData:theData toURL:theAliasURL options:0 |error|:(reference)
lns3.scpt
end createAlias:pointingTo:
lns3.scpt
on originalFromAlias:aFileOrPath asFile:fileFlag
lns3.scpt
set {theData, theError} to |NSURL|'s bookmarkDataWithContentsOfURL:theAliasURL |error|:(reference)
lns3.scpt
set theDict to |NSURL|'s resourceValuesForKeys:{NSURLPathKey} fromBookmarkData:theData
lns3.scpt
set thePath to theDict's objectForKey:(NSURLPathKey)
lns3.scpt
considering numeric strings
lns3.scpt
if fileFlag and AppleScript's version > "2.4" then
lns3.scpt
set originalURL to |NSURL|'s fileURLWithPath:thePath
lns3.scpt
return originalURL as «class furl»
lns3.scpt
return thePath as text
lns3.scpt
end originalFromAlias:asFile:
lns3.scpt
on createSymlink:aFileOrPath pointingTo:originalFileOrPath
lns3.scpt
set theLinkURL to my makeURLFromFileOrPath:aFileOrPath
lns3.scpt
set {theResult, theError} to NSFileManager's |defaultManager|()'s createSymbolicLinkAtURL:theLinkURL withDestinationURL:originalURL |error|:(reference)
lns3.scpt
end createSymlink:pointingTo:
lns3.scpt
on resolveSymlinksIn:aFileOrPath
lns3.scpt
set {theResult, theValue, theError} to theLinkURL's getResourceValue:(reference) forKey:(current application's NSURLVolumeSupportsSymbolicLinksKey) |error|:(reference)
lns3.scpt
if not (theValue as boolean) then error "This volume does not support symbolic links"
lns3.scpt
return theLinkURL's |URLByResolvingSymlinksInPath|()'s path() as text
lns3.scpt
end resolveSymlinksIn:
lns3.scpt
on createHardLink:aFileOrPath linkedTo:originalFileOrPath
lns3.scpt
set {valuesDict, theError} to originalURL's resourceValuesForKeys:{current application's NSURLVolumeSupportsHardLinksKey, NSURLVolumeURLKey} |error|:(reference)
lns3.scpt
if valuesDict is missing value then error (theError's |localizedDescription|() as text) number (theError's code() as integer)
lns3.scpt
if not ((valuesDict's objectForKey:(current application's NSURLVolumeSupportsHardLinksKey)) as boolean) then error "This volume does not support hard links"
lns3.scpt
set {theResult, volURL, theError} to theLinkURL's URLByDeletingLastPathComponent()'s getResourceValue:(reference) forKey:(NSURLVolumeURLKey) |error|:(reference)
lns3.scpt
if theResult is missing value then error (theError's |localizedDescription|() as text) number (theError's code() as integer)
lns3.scpt
if not (volURL's isEqual:(valuesDict's objectForKey:NSURLVolumeURLKey)) as boolean then error "Both items must be on the same volume"
lns3.scpt
set {theResult, theError} to NSFileManager's |defaultManager|()'s linkItemAtURL:originalURL toURL:theLinkURL |error|:(reference)
lns3.scpt
end createHardLink:linkedTo:
lns3.scpt
on contentsOf:fileOrPathA equalsContentsOf:fileOrPathB
lns3.scpt
set theURLA to my makeURLFromFileOrPath:fileOrPathA
lns3.scpt
set theURLB to my makeURLFromFileOrPath:fileOrPathB
lns3.scpt
return (NSFileManager's |defaultManager|()'s contentsEqualAtPath:(theURLA's path()) andPath:(theURLB's path())) as boolean
lns3.scpt
end contentsOf:equalsContentsOf:
lns3.scpt
on fileTypeOf:aFileOrPath
lns3.scpt
if (isPackage as boolean) then
lns3.scpt
return "package"
lns3.scpt
return "folder"
lns3.scpt
return "file"
lns3.scpt
end fileTypeOf:
lns3.scpt
on contentsOf:aFileOrPath includeInvisibles:incInvis includeFiles:incFiles includeFolders:incFolders resultType:resType
lns3.scpt
set theOptions to 0
lns3.scpt