this works in Leopard, the UI elements in Tiger are probably different
tell application "System Preferences"
activate
reveal anchor "Internet" of pane id "com.apple.preferences.sharing"
end tell
tell application "System Events"
tell process "System Preferences"
tell table 1 of scroll area 1 of group 1 of window 1
tell (1st row whose value of static text 1 is "File Sharing") to click checkbox 1
end tell
end tell
end tell
quit application "System Preferences"
Is it possible to modify the script that it definitely turns filesharing off or on (not switching). Could anybody help me?
I think i have to modify “click checkbox 1” but i have no idea what to place.
This will set it ON.
If value of checkbox 1 = 1, then it would set OFF
tell application "System Preferences"
activate
reveal anchor "Internet" of pane id "com.apple.preferences.sharing"
end tell
tell application "System Events"
tell process "System Preferences"
tell table 1 of scroll area 1 of group 1 of window 1
tell (1st row whose value of static text 1 is "File Sharing")
if (value of checkbox 1) = 0 then
click checkbox 1
end if
end tell
end tell
end tell
end tell
quit application "System Preferences"
sophisticated version, you can call startFileSharing() or stopFileSharing()
on startFileSharing()
setFileSharing(true)
end startFileSharing
on stopFileSharing()
setFileSharing(false)
end stopFileSharing
on setFileSharing(bool)
tell application "System Preferences"
activate
reveal anchor "Internet" of pane id "com.apple.preferences.sharing"
end tell
tell application "System Events"
tell process "System Preferences"
tell table 1 of scroll area 1 of group 1 of window 1
tell (1st row whose value of static text 1 is "File Sharing")
tell checkbox 1
if (get value) is ((not bool) as integer) then click
end tell
end tell
end tell
end tell
end tell
quit application "System Preferences"
end setFileSharing
Big thanks for your kind replies.
I’ve seen that the part
is language sensitive. So for my german script i’ve to write “Dateifreigabe” (which is a little bit annoying because i sometimes switch the system language. Is it possible to make this line working in “all” languages?
Yours, tom
@StefanK: ah, i see, so i can start and stop with writing either startFileSharing() or stopFileSharing() in the first line of the script. That’s fine.
in my german system (10.5.8) it’s also File Sharing.
Anyway, this script considers localized strings, adjust the property languages, token is the language identifier, value is the localized string
property languages : {{token:"de", value:"Dateifreigabe"}, ¬
{token:"en", value:"File Sharing"}, ¬
{token:"fr", value:"Partage de fichers"}, ¬
{token:"it", value:"Condivisione documenti"}}
property localizedFileSharingString : "File Sharing"
set systemLanguage to word 1 of (do shell script "defaults read -g AppleLanguages")
repeat with i in languages
if i's token is systemLanguage then
set localizedFileSharingString to i's value
exit repeat
end if
end repeat
startFileSharing()
on startFileSharing()
setFileSharing(true)
end startFileSharing
on stopFileSharing()
setFileSharing(false)
end stopFileSharing
on setFileSharing(bool)
tell application "System Preferences"
activate
reveal anchor "Internet" of pane id "com.apple.preferences.sharing"
end tell
tell application "System Events"
tell process "System Preferences"
tell table 1 of scroll area 1 of group 1 of window 1
tell (1st row whose value of static text 1 is localizedFileSharingString)
tell checkbox 1
if (get value) is ((not bool) as integer) then click
end tell
end tell
end tell
end tell
end tell
quit application "System Preferences"
end setFileSharing
error “token of item 1 of every language kann nicht in Typ reference umgewandelt werden.” number -1700 from token of item 1 of every language to reference
Hi,
because i combined some parts in an automator script to start everything i need for web-development, i use this unter 10.6 (german). It sould be easy to figure out, what to change. If you don’t get it working i’ll try to help tomorrow or on the weekend.
startFileSharing()
on startFileSharing()
setFileSharing(true)
end startFileSharing
on stopFileSharing()
setFileSharing(false)
end stopFileSharing
on setFileSharing(bool)
tell application “System Preferences”
activate
reveal anchor “Internet” of pane id “com.apple.preferences.sharing”
end tell
tell application "System Events"
tell process "System Preferences"
tell table 1 of scroll area 1 of group 1 of window 1
tell (1st row whose value of static text 1 is "Dateifreigabe")
tell checkbox 1
if (get value) is ((not bool) as integer) then click
end tell
end tell
end tell
end tell
end tell
quit application "System Preferences"
I can get file sharing to turn on but the problems surface to achieve the other things:
(1) Turning on FTP file sharing (which is an option under file sharing - which via GUI requires a bit of doing); and
(2) Turning on internet sharing, which is not as simple as turning on file sharing as it throws up a dialog box (a) if airport is turned off and (b) to prompt “Start” sharing. Again, via GUI scripting, I have got stuck.
Cheers
Andrew
Model: MacBook Pro
Browser: Safari 525.27.1
Operating System: Mac OS X (10.5)
As you can see, I have made no progress since your last intervention!
Have tried this:
do shell script "/bin/launchctl load -w " & "/System/Library/LaunchDaemons/ftp.plist" with administrator privileges
do shell script "/bin/launchctl load -w " & "/System/Library/LaunchDaemons/com.apple.AppleFileServer.plist" with administrator privileges
do shell script "/bin/launchctl load -w " & "/System/Library/LaunchDaemons/com.apple.InternetSharing.plist" with administrator privileges
The first shell script seems to work, but the second two have no effect.
At least the first shell script allows me to get around the FTP issue. Although it did prompt me for the account password. Is there any way around that?
And if you have any further suggestions to shell script the sought after result for internet sharing and file sharing, I am all ears…
Merci beaucoup, as ever. Don’t know where you get to know all this detail:)