Temp Files no longer visible

Not sure why but I can no longer find files in Temp Folders hopefully someone has ideas. My OS is Sonoma 14.5

I have given Script Debugger full disk access. I have removed and added again to confirm.

Neither the AppleScriptObjC or System Events option works.

use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions

tell application "System Events"
	set posixTempFolder to (get POSIX path of temporary items folder) as string
	set posixtempFiles to files of folder posixTempFolder whose name contains ".csv"
end tell

or

use scripting additions
use framework "Foundation"

tell application "System Events"
	set posixTempFolder to (get POSIX path of temporary items folder) as string
end tell
set listOfPaths to my getItemsIn:posixTempFolder searchedExtensions:{".csv"}

on getItemsIn:posixPathOfFolder searchedExtensions:theList
	set theNSURL to current application's class "NSURL"'s fileURLWithPath:posixPathOfFolder
	set theFileManager to current application's NSFileManager's new()
	-- get all except hidden items and items within packages
	set allURLs to (theFileManager's enumeratorAtURL:theNSURL includingPropertiesForKeys:{"path"} options:((current application's NSDirectoryEnumerationSkipsPackageDescendants) + (current application's NSDirectoryEnumerationSkipsHiddenFiles as integer)) errorHandler:(missing value))'s allObjects()
	set thePred to current application's NSPredicate's predicateWithFormat:"pathExtension IN[c] %@" argumentArray:{theList}
	set theURLs to allURLs's filteredArrayUsingPredicate:thePred
	-- convert URLs to POSIX paths 
	return (theURLs's valueForKey:"path") as list
end getItemsIn:searchedExtensions:

mcsprodart. Your first script worked for me as written on my Sonoma computer (see screenshot below). The second script did not work because “.csv” should be “csv”. After making that change, the script worked as expected.

What version Sonoma you running? Thank you for testing

My Sonoma version is 14.6.

BTW, if you are going to use ASObjC, you might want to consider using the NSTemporaryDirectory function.

use scripting additions
use framework "Foundation"

set posixTempFolder to current application's NSTemporaryDirectory()
--set posixTempFolder to (current application's NSTemporaryDirectory())'s stringByAppendingPathComponent:"/TemporaryItems"
set listOfPaths to my getItemsIn:posixTempFolder searchedExtensions:{"csv"}

on getItemsIn:posixPathOfFolder searchedExtensions:theList
	set theNSURL to current application's class "NSURL"'s fileURLWithPath:posixPathOfFolder
	set theFileManager to current application's NSFileManager's new()
	-- get all except hidden items and items within packages
	set allURLs to (theFileManager's enumeratorAtURL:theNSURL includingPropertiesForKeys:{"path"} options:((current application's NSDirectoryEnumerationSkipsPackageDescendants) + (current application's NSDirectoryEnumerationSkipsHiddenFiles as integer)) errorHandler:(missing value))'s allObjects()
	set thePred to current application's NSPredicate's predicateWithFormat:"pathExtension IN[c] %@" argumentArray:{theList}
	set theURLs to allURLs's filteredArrayUsingPredicate:thePred
	-- convert URLs to POSIX paths 
	return (theURLs's valueForKey:"path") as list
end getItemsIn:searchedExtensions:
1 Like

So started to type a response that both ASObjC worked after removing the period and pointing out System Events doesn’t work…looked in Privacy and Security and ‘System Events’ no longer had permission…annoying that it changed and that I forgot it required permissions in addition to Script Debugger…but fixed. I’m updating my code to your suggestion though it’s much better! Thanks for your quick responses.

1 Like