Since you already have the full path of the file (see
bold line above) I don't understand why you're deconstructing the file
name and file extension and then reconstructing them in your Finder
code.
But I may be missing something.
If you're trying to find a file by name
(non-recursively) then something like this is very fast:
-------------------------------------------------------------------------------------------
# Auth: Christopher
Stone { Heavy lifting by Shane Stanley }
# dCre: 2016/05/02 03:47
# dMod: 2016/05/23
10:58
#
Appl: AppleScriptObjC
# Task: Acquire posix paths of files where its name
matches the given regular _expression_.
# Aojc: True
# Libs: None
# Osax: None
# Tags:
@Applescript, @ASObjC, @Script, @Acquire, @POSIX_Path, @RegEx
-------------------------------------------------------------------------------------------
use AppleScript version "2.4"
use framework "Foundation"
use scripting additions
-------------------------------------------------------------------------------------------
set regExPattern to "(?i).+\\jpe?g$"
set sourceFolder to POSIX path of (path to desktop folder)
set fileManager to
current
application's NSFileManager's defaultManager()
set aURL to current application's |NSURL|'s fileURLWithPath:sourceFolder
set directoryContents to
fileManager's contentsOfDirectoryAtURL:aURL includingPropertiesForKeys:{} options:0 |error|:(missing value)
set foundItemList to
current
application's NSPredicate's predicateWithFormat:("lastPathComponent
matches '" & regExPattern & "'")
set foundItemList to
directoryContents's filteredArrayUsingPredicate:foundItemList
set foundItemList to foundItemList as list --> List of as «class
furl» which can be worked with much like an alias list.
# set foundItemList to (foundItemList's
valueForKey:"path") as list --> List of POSIX Paths
-------------------------------------------------------------------------------------------