I have a script that needs to branch on whether or not a file (or folder) is on the Clipboard.
###What is Best Method to Detect (Check for) a File on the Clipboard?
Here’s the simple script I have. Seems to work fine, and runs fast.
But I’d like to know if there is a better or faster method.
Any ideas?
set clipRec to the clipboard as record
try
set fileObj to «class furl» of clipRec
set isFileOnCB to true
on error
set isFileOnCB to false
end try
return isFileOnCB
That will only discover 1 file/folder on the clipboard even if there are more than one.
It’s a nasty little limitation, although for some tasks it may be enough information.
To get more you have to use AppleScriptObjC.
------------------------------------------------------------------------------
use framework "Foundation"
use framework "AppKit"
use scripting additions
------------------------------------------------------------------------------
set theClipboard to current application's NSPasteboard's generalPasteboard()
set theURLs to theClipboard's readObjectsForClasses:{current application's class "NSURL"} options:(missing value)
set theCount to theURLs's |count|()
------------------------------------------------------------------------------