Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > AppleScript to Turn on Filesharing on Remote Machine

AppleScript to Turn on Filesharing on Remote Machine
Thread Tools
selowitch
Mac Elite
Join Date: Nov 2003
Location: Rockville, MD
Status: Offline
Reply With Quote
Jul 24, 2006, 07:45 PM
 
I am thisclose to making this work:
Code:
using terms from application "Finder" tell application "Finder" of machine "eppc://myusername:[email protected]" do shell script "/usr/sbin/AppleFileServer" end tell end using terms from
But it doesn't quite make it. No error message, but it doesn't appear to work. I've tried changing the target app to "System Events," tried appending "sudo" to the start of the script, but no dice. I even added "password x with administrator privileges" with no luck. Somebody help me. Thanks.

Could it be, ironically, that Filesharing has to be on for this to work? I know Apple Remote Events is set to "on" on the target machine....
     
Chuckit
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Jul 24, 2006, 10:03 PM
 
My knowledge of remote AppleScripting is pretty limited, but as an alternative, since you are basically just running a shell script, don't you think a shell script might be a better fit for this?
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
selowitch  (op)
Mac Elite
Join Date: Nov 2003
Location: Rockville, MD
Status: Offline
Reply With Quote
Jul 24, 2006, 10:16 PM
 
Originally Posted by Chuckit
My knowledge of remote AppleScripting is pretty limited, but as an alternative, since you are basically just running a shell script, don't you think a shell script might be a better fit for this?
Perhaps. But my knowledge of shell scripting is pretty limited. :-) Also, I intend to follow it up with more AppleScript code.
( Last edited by selowitch; Jul 25, 2006 at 08:06 AM. )
     
arcticmac
Dedicated MacNNer
Join Date: Apr 2004
Status: Offline
Reply With Quote
Jul 25, 2006, 02:54 PM
 
Originally Posted by selowitch
Perhaps. But my knowledge of shell scripting is pretty limited. :-) Also, I intend to follow it up with more AppleScript code.
Well, you COULD just write the shell script, include it inside the applescript bundle (or whatever), and be done...

Just to check, there's (IIRC) a setting someplace to enable remote Apple Events (I think it's in the Sharing Prefpane). doesn't that need to be on?
     
selowitch  (op)
Mac Elite
Join Date: Nov 2003
Location: Rockville, MD
Status: Offline
Reply With Quote
Jul 25, 2006, 03:50 PM
 
Originally Posted by arcticmac
Well, you COULD just write the shell script, include it inside the applescript bundle (or whatever), and be done...
Fine. Would you care to tell me how?
Originally Posted by arcticmac
Just to check, there's (IIRC) a setting someplace to enable remote Apple Events (I think it's in the Sharing Prefpane). doesn't that need to be on?
Remote Apple Events is definitely enabled on the remote machine and I'm pretty sure that, yes, that is necessary for this to work.
( Last edited by selowitch; Jul 25, 2006 at 04:09 PM. )
     
arcticmac
Dedicated MacNNer
Join Date: Apr 2004
Status: Offline
Reply With Quote
Jul 25, 2006, 05:49 PM
 
well, the shell script can actually *probably* be one line - I think an appropriately crafted SSH command would do it, so you could just write the statement. I think something like this...

Code:
do shell script "/usr/bin/ssh [email protected] /usr/sbin/AppleFileServer"
or you could put it in a separate file,
Code:
#!/bin/sh ssh [email protected] /usr/sbin/AppleFileServer; exit 0;
and run that

Code:
do shell script "~/myshellscript"
That said, I haven't played around with this, and it still leaves how you're going to authenticate... you might be able to get applescript to send a newline and then your password in that first option, but...

play around.
     
selowitch  (op)
Mac Elite
Join Date: Nov 2003
Location: Rockville, MD
Status: Offline
Reply With Quote
Jul 25, 2006, 07:47 PM
 
OK, I think I've made some progress, although it is not exactly working yet. Stay with me, folks.
I think this AppleScript, once corrected, may do the trick, without a tell block:
Code:
do shell script "/usr/bin/ssh johnsmith:[email protected] /usr/sbin/AppleFileServer"
No, it doesn't "work" exactly, but we're getting somewhere. Any further ideas?
     
arcticmac
Dedicated MacNNer
Join Date: Apr 2004
Status: Offline
Reply With Quote
Jul 25, 2006, 07:56 PM
 
Originally Posted by selowitch
Any further ideas?
my further idea would be that you try running the command in a terminal window until you can get it to a single line that does what you want. THEN put it into the applescript. The terminal will give you better debugging info that AppleScript. Also, remember, manpages are your friend. man ssh in a terminal to start, see what gives by reading that. It's more efficient for you to read it than for me to read it and tell you about it.
     
besson3c
Clinically Insane
Join Date: Mar 2001
Location: yes
Status: Offline
Reply With Quote
Jul 25, 2006, 08:09 PM
 
do shell script "/usr/bin/ssh johnsmith:[email protected] /usr/sbin/AppleFileServer"
Try changing this to:

do shell script "/usr/bin/ssh [email protected]: /usr/sbin/AppleFileServer"

You can't pass off your password to SSH this way (and I hope that wasn't your personal password you just published). What you can do that is even better is setup SSH to connect via public/private key pairs. This approach is secure and well documented.

Here is a great tutorial on all things SSH. There is a section here on how to setup authentication via keys:

http://www.suso.org/docs/shell/ssh.sdf
     
selowitch  (op)
Mac Elite
Join Date: Nov 2003
Location: Rockville, MD
Status: Offline
Reply With Quote
Jul 29, 2006, 05:09 PM
 
Originally Posted by arcticmac
my further idea would be that you try running the command in a terminal window until you can get it to a single line that does what you want. THEN put it into the applescript. The terminal will give you better debugging info that AppleScript. Also, remember, manpages are your friend. man ssh in a terminal to start, see what gives by reading that. It's more efficient for you to read it than for me to read it and tell you about it.
I'm trying this approach now (i.e., figuring out the proper Terminal command first).
     
selowitch  (op)
Mac Elite
Join Date: Nov 2003
Location: Rockville, MD
Status: Offline
Reply With Quote
Jul 29, 2006, 05:19 PM
 
Note: No, besson3c, I did not just publish my password. The ones I did publish were made up. So, sleep soundly! :-)

OK, here's my progress so far:

1. Turning Filesharing On Locally via AppleScript
Code:
do shell script "/usr/sbin/AppleFileServer/" password "mypassword" with administrator privileges
2. Turning Filesharing Off Locally via AppleScript
Code:
do shell script "/usr/bin/killall AppleFileServer/" password "mypassword" with administrator privileges
These two scripts work great with just one line apiece, no tell block or anything. There is a slight delay, and if you are viewing the Services tab of the Sharing pane of System Preferences, you may need to switch away from it and back again to see the checkmark indicating Filesharing has been toggled on or off. But it works.

3. Turning Filesharing On Locally via Terminal
Here's a transcript of a Terminal session that successfully achieves this:
Code:
Last login: Sat Jul 29 19:38:54 on ttyp1 Welcome to Darwin! Sam-Elowitchs-Computer:~ samelowitch$ sudo /usr/sbin/AppleFileServer/ Password: Sam-Elowitchs-Computer:~ samelowitch$
4. Turning Filesharing Off Locally via Terminal
Here's a transcript of a Terminal session that successfully achieves this:
Code:
Last login: Sat Jul 29 19:38:54 on ttyp1 Welcome to Darwin! Sam-Elowitchs-Computer:~ samelowitch$ sudo /usr/bin/killall AppleFileServer/ Password: Sam-Elowitchs-Computer:~ samelowitch$
( Last edited by selowitch; Jul 30, 2006 at 04:20 PM. )
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 10:50 PM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,