Help needed with a simple launch Script

I know that this is a simple script and most of you could write in your sleep, but this is my first attempt to use applescript (to do any type of ‘programming’ in fact), and I’m not afraid to admit I need your help.

I am trying to write a simple script to launch an application (SMB Manager) to facilitate logging onto an SMB server (keychains don’t work). All I need to script is launch the application SMB Manager, then hit the default ‘Connect’ button, then quit the SMB Manager. I am using CronniX to automate launching this script every morning to make the connection and then running backup software.

Here’s my first feeble attempt - only took me 3 hrs to learn this much and to get it to work - and it doesn’t even press the blue ‘connect’ button or quit when complete. Hence, my plea for help!

tell application “Finder”
open file “Macintosh HD:Applications:SMB Manager”
end tell
:oops:

Thanks much!
TB

I was able to borrow a chunk of script from another post to add the hit ‘return’ key on the launched application and then quit, and this seems to do the trick. I am hoping that this is just the start of my scripting experience, so I would be interested in hearing any comments you might have on this little script, and whether there might be a better way of doing this.

tell application “Finder”
open file “Macintosh HD:Applications:SMB Manager”
delay 1
tell application “System Events”
keystroke (ASCII character of 13)
delay 1
keystroke “q” using command down
end tell
end tell

Cheers.
TB

Hi TB,

There’s nothing wrong with your script, but you don’t really need to involve the Finder - every app. should respond to activate. I don’t know SMB Manager, but does this do the job?

tell application "SMB Manager"
	activate
	delay 1
	tell application "System Events" to keystroke (ASCII character of 13)
	delay 1
	quit
end tell

Best

John M

John M -

Your script also did the trick but ended with an error message:

“SMB Manager got an error: Connection is invalid.”

Not sure why the error message, but I appreciate the feedback regarding Finder.

Cheers.
TB

Maybe this will eliminate the error.

tell application "SMB Manager" to activate 
delay 1
tell application "System Events" to keystroke (ASCII character of 13) 
delay 1 
tell application "SMB Manager" to quit

– Rob

Try this (don’t save this as a script application that also has “SMB” in its name):

Jon


[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]

Jon,
That works great.

One final question - this dows a great job of logging my into the remote SMB server and quitting the SMB Manager application. However, it leaves the server finder window open and in front of whatever application I am using, but not slected (active). Is it possible to script selecting and closing of the server finder window?

Perhaps using :
tell application “System Events”
keystroke “w” using (command down)
end tell

If so, how do I select the server window to be the window that closes?

Thanks y’all.
TB

Just add the following to your script:

Jon


[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]

No luck - did not close the finder window.
TB