1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
| --affiche une fenêtre de choix
display dialog "Ce script va cacher le compte admin,voulez vous effectuer ce changement sur un ordinateur distant ou sur cet ordinateur?" buttons {"mac distant", "ce mac", "Annuler"} default button 2
--fonction qui permet d'avoir le chemin du script (pratique quand on change le script de place) et de changer ce chemin pour indiquer le chemin du fichier qui va être copié sur l'ordinateur distant: la variable s'appelera haystack
--Get the paths of all selected files
set strFilePath to {}
tell application "Finder"
repeat with objItem in (get selection)
set end of strFilePath to POSIX path of (objItem as text)
end repeat
end tell
--Copy the file paths to the clipboard
set {strDelimeter, text item delimiters} to {text item delimiters, return}
set the clipboard to strFilePath as text
set text item delimiters to strDelimeter
set haystack to strFilePath
set needle to "extensions/adminhidercomplement.scpt"
set replacement to "Get-scriptdirectory.scpt"
search_replace(haystack, needle, replacement)
on search_replace(haystack, needle, replacement)
set old_delimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to needle
set temp_list to every text item of haystack
set AppleScript's text item delimiters to replacement
set return_value to temp_list as text
set AppleScript's text item delimiters to old_delimiters
return return_value
end search_replace
display dialog haystack as text with title "Path(s) copied to clipboard" with icon note giving up after 10 buttons {"Close"} default button "Close"
--actions si on veut effectuer le script en local
if the button returned of the result is "ce mac" then
tell application "Terminal"
activate
do shell script "sudo -s dscl . -create /Users/admin UniqueID 401" with administrator privileges
do shell script "sudo chown -R admin /Users/admin/" with administrator privileges
do shell script "sudo defaults write /Library/Preferences/com.apple.loginwindow Hide500Users -bool YES" with administrator privileges
end tell
else
-- actions si on veut efféctuer le script sur un ordinateur distant
display dialog "Quel est l'adresse IP de l'ordinateur distant?" default answer "" buttons {"OK"} default button 1
display dialog text returned of the result & "
" & "Il sagit du mac " & "? Etes vous sûr de vouloir continuer?" buttons {"Ok", "Annuler"}
if the button returned of the result is "Ok" then
tell application "Terminal"
activate
do shell script "scp -r haystack admin@" & text returned of the result & ":/Users/admin/Desktop/"
do shell script "ssh admin@" & text returned of the result
do shell script "osascript -l /Users/admin/Desktop/adminhidercomplement.scpt"
end tell
end if
end if |