3

I have been using apple script for updating display for files and folders in finder. This is simplified version of that script:

tell application "Finder"
    tell window 1 to update items
end tell

I can see that since 10.8 (Mountain Lion) update command is not properly executed or is not executed at all. Until 10.8 everything was working perfectly - Immediately after update command all icons got redrawn. I use this for showing overlay icons.

Have any of you encountered same problem? I blame finder having changed apple script api, because, if I touch -a -m file, it gets updated. So there is for sure some way to update it.

Parag Bafna
  • 22,812
  • 8
  • 71
  • 144
Marcel Vyberal
  • 101
  • 1
  • 6

2 Answers2

2

You can create visible file in finder to refresh finder window.

tell application "Finder"
    set currentPath to (POSIX path of (target of front window as alias))
    set filePath to currentPath & "UUID" --create UUID
    do shell script "touch \"" & filePath & "\""
    delay 0.5
    do shell script "rm \"" & filePath & "\""
end tell
Parag Bafna
  • 22,812
  • 8
  • 71
  • 144
  • Thanks for sharing this Parag. I have an app bundle on my desktop. I changed the icns file in the resources folder of it but its not updating. When i try to run this code i get this error: `AppleScript Error - Can’t make «class fvtg» of window 1 of application "Finder" into type alias.` do you know how i can fix this? Do you think this will refresh my icon? – Noitidart Jan 12 '15 at 19:57
  • Oh im using 10.9 btw but im looking for a solution that works in all >= 10.5 – Noitidart Jan 12 '15 at 21:34
  • @Parag Banfna this script is working or execute only first time, then this script won't execute or working..:( Can you please let me know why its happens? – jigs Oct 29 '15 at 09:32
1

I am having the same exact issue as you. I was about to release my application once I built it with the 10.8 SDK, but Mountain Lion just broke both my "Refresh Finder Windows" and "Show/Hide Hidden Files" menu options. I have tried everything to no avail. The only thing that seems to help is if you wait 60-90 seconds before writing to the Finder Preferences again.

In Terminal:

defaults write com.apple.Finder AppleShowAllFiles TRUE && killall Finder

Wait about a minute to a minute and a half, then reverse the command like so:

defaults write com.apple.Finder AppleShowAllFiles FALSE && killall Finder

(I don't know how to refresh Finder via Terminal, but maybe that delay will help you out in some way.)

That is the only way I currently know of to get the Finder windows to do anything I want them to. Very frustrating; I hope someone can figure this out soon or one of my major selling points just vanished.

-Chris

Chris L.
  • 11
  • 1
  • I saw that delay too. When I send update command to finder, it takes some time (probably that delay) to really refresh icons. It seems like apple have done some "optimization" of finder, so it is not refreshing immediately. Anyway it is of no use for me, since I need icons redrawn in realtime. – Marcel Vyberal Aug 27 '12 at 15:32