简体   繁体   中英

MacOS Sierra & SMB & Synology NAS & Applescript crashes Finder

I've discovered a bug that I don't know how to fix. So I have an Applescript that tells the mac to highlight a certain file in an already opened Finder window connected to a shared folder on a Synology NAS server. Here's the Applescript:

set theFile to "West Office Files:_Scan Inbox:LAR:1002.pdf"
tell application "Finder"
reveal document file theFile
end tell

An error pops up saying that Finder got an error: document file "West Office Files:_Scan Inbox:LAR:1002.pdf" doesn't understand the "reveal" message . I have also tried using "select" instead of "reveal" and the problem persists. However, I just discovered it doesn't throw an error the first time the script is ran. But if I run it again to select a different file (but in same folder location) it then throws the error.

Then strange things begin to happen in Finder. Can't click on a finder window showing files, can't close any windows. Sometimes Finder will start popping up what I call "shadow boxes" which is the drop shadow of a window, but the window is invisible. Finder won't correct itself and the only fix I've found is to quickly log out the user to the Mac login screen and log back in. If I don't Finder will get worse and ultimately requires a force restart.

This is ONLY happening with MacOS Sierra (any sub version) and when connected to a Synology NAS server (any version DSM 6+) via SMB. AFP works fine, pre-Sierra Mac OSes work fine, and even when connected to an old Mac OS (Lion) Server via SMB or AFP there is no problem.

Anyone experiencing this? Any ideas for a solution?

Untested (im on mobile) but you need to transform osx path to posix file:

set theFile to POSIX file (POSIX path of "West Office Files:_Scan Inbox:LAR:1002.pdf")

tell application "Finder" to reveal theFile

With help from Pat_Morita I found a solution to the problem. Am posting it here to help others who use Synology NAS servers and Macs.

set theFile to POSIX file (POSIX path of "/Volumes/West Office Files/_Scan Inbox/LAR/1002.pdf") as alias
tell application "Finder"
    set selection to {}
    select theFile
end tell

Where the error was occurring was specifically when the AppleScript would tell the Finder to highlight a file and there was a file already highlighted. In MacOS Sierra it would throw an error in the Apple Event right when it moves away from the currently selected file. So adding in the "set selection to {}" has Finder deselect what is highlighted before selecting the next file. I also went with using POSIX for the file path by recommendation from this forum.

UPDATE ---

False alarm on finding a fix, well... sorta.

The error is still thrown and seems to only be happening when a Finder window is in Cover Flow view. All the other views work fine. Also, I discovered the bug is happening when MacOS Sierra is connected via AFP as well, not just SMB. I changed the AppleScript a bit:

set theFile to "West Office Files:_Scan Inbox:LAR:1002.pdf" as alias
tell application "Finder"
   set selection to {}
   select file theFile
end tell

Learned that Finder doesn't really care if the file path is set up via POSIX or not. Also added "file" to the select line.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM