Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Applescript Network Drives Issue

We are mainly a Windows based business, but we are adding MAC's for our design users and a few user in development. I'm having an issues with Apple-script adding network drives without an error. Below is the basic script I am using to add the drives and I have them run as an application every time a user logs in. Thing is it will randomly work and then randomly not work a few minutes later if the machine is rebooted or logged off of. I have ran the script in Apple-Script and the error comes up maybe half the time. If I use the application script I saved from Apple-Script the same thing will happen. Hit or miss. I don't get why it would work one moment and not the next. It always comes back with a "AppleEvent handler failed finder got an error (-10000)" if it doesn't work or at times "expected end of line, etc. but found identifier." The drives will be added like I want them to, but the windows and the error will stay on the screen when they should close out. This happens with all users who have this setup and the file are created and saved under their user names because at first I was getting errors saying the user couldn't access the file. Normally I would deal with it, but the users love to complain they need to exit windows on login. If I hit the edit button on the error it will highlight the "close every window" section of the text. If I close out and reopen the same file it may run just fine no errors or may not work with the same error. Is there a better way to close out of all the finder windows using script to stop this from happening? Any help would be appreciated. Thanks.


Saved as an application and runs on login per user (each has a different application file):


tell application "Finder"

open location "smb://server/folder$"

delay 1

open location "smb://server/folder"

delay 1

(ADD MORE NETWORK LOCATIONS IF NEEDED)

end tell

delay 3

tell application "Finder" (also tried: tell application "finder" to close every window)

close every window

end tell

MacBook Air, OS X Yosemite (10.10.3)

Posted on Apr 23, 2015 7:12 AM

Reply
5 replies

Apr 23, 2015 2:07 PM in response to kinch619

Hi,


I do it this way.

Once I have logged on to a Drive the first time I find the Folder if I want only that and have that on the Desk top.

I then drag it to the System Preferences > User and Groups > My account > Login Items and it will restore that link each time I star that computer.


I link to my other Mac this way and to an NAS Drive and my Folder on it.



User uploaded file

10:07 pm Thursday; April 23, 2015


 iMac 2.5Ghz i5 2011 (Mavericks 10.9)
 G4/1GhzDual MDD (Leopard 10.5.8)
 MacBookPro 2Gb (Snow Leopard 10.6.8)
 Mac OS X (10.6.8),
 Couple of iPhones and an iPad

Apr 24, 2015 6:52 AM in response to Ralph-Johns-UK

Hey Ralph, thanks for the reply. I should have mentioned that I tried that way as well, but it would still end up opening a finder(?) window that the user had to exit out of every time they logged into the MAC. They are insatiable users, so they will just end up complaining about that one as well. I selected that hid option hoping that would add the drives, but not show the folders each time. No luck. Not sure if there is something that can be added to the smb:// to hid all those windows or close them out in the fashion that you mentioned. For now I change out "close every window" with "quit" so it closes out the program once it is done as a temp fix. Hopefully there is a better way then that, but again thanks for the suggestion.

Apr 24, 2015 12:56 PM in response to kinch619

Humm,


On my G4 that is running Leopard I tend to leave window showing the Folder that contains my off computer storage on the NAS drive.

The NAS has 3 physical drives. The Original was set up then I added to more but as separate space (linked) after my son managed to fill the first drive. (along with his and mine Time Machine Backups)
SO I am logged in to the NAS then the Extended drives as I called them and that shows on the Desktop as a Drive with the window open.


On my iMac running Yosemite I Show the NAS Extended and two USB drives that are on my MacBook Pro.

All three of these then show as windows at Start up but I am not sure if that is the default action or the way I had the Drives "Open" when I dragged them to the Login Items list.


I tested on my MacBook Pro (Snow Leopard) and logged in to the G4 and added two of it's Drives to the Desktop on the MacBook Pro.

I then closed the windows showing for that - then dragged them to the Login items List and restarted. This asked me for the Login User ID and Password (Didn't get saved properly) but then showed windows as well.


I had not really equated the windows as happening every time.


I had asked th Hosts to move this thread to Apple Technologies as that is where AppleScript questions tend to end up.

I have used AppleScript with iChat and early Messages versions but apple have seemingly changed the way it works with Messages to the point it is unusable.

I did feel that Script-wise you might find a better solution here.


Going back to a time when iChat had separate Chat windows (as well as anything from the Preferences or Menus that could be open someone created this Script


using terms from application "Messages"

on AV invite

tell application "iChat"

set allChatWindows to every window

set completed to false

repeat with currentWindow in allChatWindows

set windowname to the name of currentWindow

if (not completed) then

if ((windowname is not ¬

"Audio/Video") and (windowname starts with ¬

"Audio" or windowname starts with ¬

"Video")) then

set Status Message to windowname

set completed to true

else if (windowname does not contain ¬

"General" and windowname does not contain ¬

"Doctor" and windowname does not contain ¬

"Activity" and windowname does not contain ¬

"File" and windowname does not contain ¬

"Accounts" and windowname does not contain ¬

"Messages" and windowname does not contain ¬

"Alerts" and windowname does not contain ¬

"Audio/Video" and windowname does not contain ¬

"Chax" and windowname does not contain ¬

"AIM" and windowname does not contain ¬

"Contacts" and windowname does not start with ¬

"Chat" and windowname does not contain ¬

"Chats" and windowname does not contain ¬

"Bonjour") then

set Status Message to "Audio Chat with " & windowname

set completed to true

end if

delay 0.2

end if

end repeat

set volume input volume 85

delay 0.2

set volume output volume 80

delay 0.2

set Status Message to "I was Busy but now I am not"

end tell

end AV invite

end using terms from



I have run it about once, back in the day. The process of moving the Messages changed part of this at the top but not later references to iChat.

It is supposed to presume things like the Preferences are Open where the window would take on the name of the section that was selected (General, Accounts, Messages (back then) Audio/Video and Alerts plus the iChat Add-on Chax) or various Menus items like the Connection Doctor and it's sub sections.


It then displays that the Chat type and the Buddy's name as the Status Method


As many of my Buddies prefer to try to keep as lower profile on the Internet as they can I have not used it in "Real Life" as it were.


However it might give clues that windows might need to be closed by Name.




User uploaded file

8:56 pm Friday; April 24, 2015


 iMac 2.5Ghz i5 2011 (Mavericks 10.9)
 G4/1GhzDual MDD (Leopard 10.5.8)
 MacBookPro 2Gb (Snow Leopard 10.6.8)
 Mac OS X (10.6.8),
 Couple of iPhones and an iPad

Apr 30, 2015 6:18 AM in response to kinch619

A couple of things come to mind.


One it that you're using the wrong (or at least, not ideal) way to connect to a volume. Technically, open location will work, but it's guaranteed to open the corresponding Finder window because that's the point of open...


Instead you might consider the 'mount volume' command:


mount volume "smb://server/folder$"


This is a standard/built-in command and doesn't need to be inside a 'tell application "Finder"' block and should (untested) have the benefit of not opening the corresponding window.


Even if it does, it's interesting that the script errors on the 'close every window' command since I'd expect that to be the least likely command to fail. That said, you should at least be able to suppress the error message by encapsulating the command in a try/end try block:


tell application "Finder"

try


close every window

end try

end tell


This has the effect of catching the error so that it won't bother the user (although, of course, the windows may still be open)

Applescript Network Drives Issue

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.