set wanted_boot_arg to "nvda_drv=1"
set comment to "# it forces Nvidia Webdriver to activate"
try
set csrutil_status to do shell script "csrutil status"
if csrutil_status contains "NVRAM Protections: disabled" then set nvram_protection to false
if csrutil_status contains "NVRAM Protections: enabled" then set nvram_protection to true
if csrutil_status is "System Integrity Protection status: disabled" then set nvram_protection to false
on error
set nvram_protection to false -- we don't know, let it run in error in case...
end try
try
set boot_args to do shell script "nvram boot-args"
on error -- if nvram-bootargs is not set it returns an error
set boot_args to ""
end try
if boot_args is not in {"", "boot-args "} then
set old_boot_args to (characters 11 thru -1 of boot_args) as text
set old_boot_args_to_display to old_boot_args
else
set old_boot_args to ""
set old_boot_args_to_display to "none"
end if
try
if boot_args does not contain wanted_boot_arg then
activate me
set button_returned to button returned of ¬
(display dialog comment & return & return & "found: " & old_boot_args_to_display & return & return & "but no " & wanted_boot_arg & " in boot-args" & return & return & "press OK to add" & return & return & "(admin password needed)" buttons {"no", "OK"} default button "OK" with title "Macschrauber's boot-arg adder")
if button_returned is "no" then return
if nvram_protection then
display dialog "System integrity protection for NVRAM is enabled" buttons {"OK"} default button 1
return
end if
if old_boot_args is not "" then
set boot_arg_to_add to space & wanted_boot_arg -- to add to present boot-args a space char is needd
else
set boot_arg_to_add to wanted_boot_arg
end if
do shell script "nvram boot-args='" & old_boot_args & boot_arg_to_add & "'" with administrator privileges
display dialog "New setting: " & return & (do shell script "nvram boot-args") with title "Macschrauber's boot-arg adder" buttons ("OK") default button 1
--else
--display dialog "nvram boot-args already contains:" & return & wanted_boot_arg & return & return & "current setting: " & return & boot_args with title "Macschrauber's boot-arg adder" buttons ("OK") default button 1
end if
on error errortext number errornumber
display alert (errornumber as string) & return & errortext
if errortext contains "not permitted" then display dialog "system integrity protection for nvram is enabled" buttons {"OK"} default button 1
end try