Finder Not Updating

I have been chasing my tail for hours over this… probably NOT an Xojo problem. but hoping there is an Xojo solution.

I have an app that creates a multi-level folder structure, and then creates/copies files into the various locations.
Sometimes the program runs and reports no errors, but Finder says there are “No Items” in the newly created top level folder.
So I have been busting my backside trying to figure out why sometimes it works,and sometimes it didn’t.

Turns out, my app WAS working, and WAS creating files… but I would have to manually navigate via Finder to get the Finder display to update

Is there someway I get get Xojo to issue (shell?) command to force the update, so when my apps completes I see the true file count in the Finder window???

imagine item 1 of front window is the folder you want a refresh:

tell application "Finder" set fw to front window tell item 1 of fw to update return name of item 1 of fw end tell

Maybe it’s just Spotlight acting weird? What happens when you do a killall Spotlight in the Terminal?

I will try both those… would prefer to avoid AppleScript.

If I do a “Relaunch” of finder via the “Force Quit” window, it updates, but that is not a transparent solution :frowning:

Yet that is, to my knowledge, the best way to automate it from within a Xojo app.

It is essentially what happens with a little app I downloaded before which you then drag and add to the Finder toolbar, yielding a refresh icon. I got that app here but it leads to a broken download link now. However, drilling into the app contents it is a script that is quite similar to what Emile posted:

tell application "Finder"
	repeat with i from 1 to count of Finder windows
		tell window i
			try
				update every item with necessity
			end try
		end tell
	end repeat
end tell

If you use something like Alfred or Spark you can also assign a shortcut key that is only active within Finder allowing you to use something like Cmd+R which Finder otherwise does not use.

Actually, not sure that Alfred will let you do an app specific shortcut key. But Better Touch Tool can quite easily. And just copy the above Apple script into a new shortcut. I should have done that long ago; I was just using the toolbar icon to perform the function.