Skip to content
This repository has been archived by the owner on Nov 14, 2017. It is now read-only.

Commit

Permalink
Merge pull request #47 from matt-cahill/disable_PW_pref_fix
Browse files Browse the repository at this point in the history
fix for allowPasswordChange = false
  • Loading branch information
macmule committed Feb 20, 2016
2 parents 858beda + c88a251 commit daa0884
Showing 1 changed file with 48 additions and 21 deletions.
69 changes: 48 additions & 21 deletions ADPassMon/ADPassMonAppDelegate.applescript
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,9 @@ Enable it now?" with icon 2 buttons {"No","Yes"} default button 2)
my statusMenu's itemWithTitle_("Refresh Kerberos Ticket")'s setEnabled_(1)
-- Set variable to boolean
set allowPasswordChange to allowPasswordChange as boolean
tell defaults to set my pwPolicyURLButtonTitle to objectForKey_("pwPolicyURLButtonTitle") as string
tell defaults to set my pwPolicyURLButtonURL to objectForKey_("pwPolicyURLButtonURL") as string

-- If password change is allowed, show
if allowPasswordChange is true
my statusMenu's itemWithTitle_("Change Password…")'s setEnabled_(1)
Expand Down Expand Up @@ -498,6 +501,8 @@ Enable it now?" with icon 2 buttons {"No","Yes"} default button 2)
my statusMenu's itemWithTitle_("Refresh Kerberos Ticket")'s setEnabled_(1)
-- Set variable to boolean
set allowPasswordChange to allowPasswordChange as boolean
tell defaults to set my pwPolicyURLButtonTitle to objectForKey_("pwPolicyURLButtonTitle") as string
tell defaults to set my pwPolicyURLButtonURL to objectForKey_("pwPolicyURLButtonURL") as string
-- If password change is allowed, show
if allowPasswordChange is true
my statusMenu's itemWithTitle_("Change Password…")'s setEnabled_(1)
Expand Down Expand Up @@ -911,22 +916,25 @@ Enable it now?" with icon 2 buttons {"No","Yes"} default button 2)
pwPolicyDisplay_(me)
end if
-- Open System Preferences
tell application "System Preferences"
try -- to use UI scripting
set current pane to pane id "com.apple.preferences.users"
activate
delay 1
tell application "System Events"
tell application process "System Preferences"
click radio button "Password" of tab group 1 of window "Users & Groups"
click button "Change Password…" of tab group 1 of window "Users & Groups"
click button "Change Password…" of window 1
set allowPasswordChange to allowPasswordChange as boolean
if allowPasswordChange is true
tell application "System Preferences"
try -- to use UI scripting
set current pane to pane id "com.apple.preferences.users"
activate
delay 1
tell application "System Events"
tell application process "System Preferences"
click radio button "Password" of tab group 1 of window "Users & Groups"
click button "Change Password…" of tab group 1 of window "Users & Groups"
click button "Change Password…" of window 1
end tell
end tell
end tell
on error theError
errorOut_(theError, 1)
end try
end tell
on error theError
errorOut_(theError, 1)
end try
end tell
end if
else
-- If Behaviour 2 is enabled, then use the different password change mechanism
-- Close the Prefs window if open
Expand All @@ -937,11 +945,15 @@ Enable it now?" with icon 2 buttons {"No","Yes"} default button 2)
pwPolicyDisplay_(me)
end if
-- If user did not chose to update externally or was not prompted, then continue
if pwPolicyUpdateExternal is false
-- Set passwordPromptWindows settings
set my enablePasswordPromptWindowButton2 to false
set my passwordPromptWindowText to changePasswordPromptWindowText
showPasswordPromptWindow_(me)
set allowPasswordChange to allowPasswordChange as boolean
set pwPolicyUpdateExternal to pwPolicyUpdateExternal as boolean
if allowPasswordChange is true
if pwPolicyUpdateExternal is false
-- Set passwordPromptWindows settings
set my enablePasswordPromptWindowButton2 to false
set my passwordPromptWindowText to changePasswordPromptWindowText
showPasswordPromptWindow_(me)
end if
end if
end if
end changePassword_
Expand Down Expand Up @@ -1231,6 +1243,8 @@ Enable it now?" with icon 2 buttons {"No","Yes"} default button 2)
tell defaults to set my pwPolicyURLButtonURL to objectForKey_("pwPolicyURLButtonURL") as string
tell defaults to set my pwPolicyURLButtonBrowser to objectForKey_("pwPolicyURLButtonBrowser") as string
tell defaults to set my pwpolicyButton to objectForKey_("pwPolicyButton") as string
-- Reset pwPolicyUpdateExternal so it's state isn't remembered accross multiple policy display calls
set pwPolicyUpdateExternal to false
-- If either pwPolicyURLButtonTitle or pwPolicyURLButtonURL is not set, then display standard pwPolicy prompt
if pwPolicyURLButtonTitle is "" or pwPolicyURLButtonURL is ""
-- If pwPolicyButton is not set
Expand All @@ -1241,11 +1255,24 @@ Enable it now?" with icon 2 buttons {"No","Yes"} default button 2)
else
-- Display password policy dialog with custom button
tell application "System Events" to display dialog pwPolicy with icon 2 buttons {pwPolicyButton}
end if
-- Set variable to boolean
set allowPasswordChange to allowPasswordChange as boolean
-- If password change is not allowed, then proceed
if allowPasswordChange is false
-- If password change is disabled, then don't proceed.
set pwPolicyUpdateExternal to true
end if
-- If both pwPolicyURLButtonTitle or pwPolicyURLButtonURL are set, then display second button
else if pwPolicyURLButtonTitle is not equal to "" and pwPolicyURLButtonURL is not equal to ""
-- Display password policy dialog
tell application "System Events" to display dialog pwPolicy with icon 2 buttons {"OK", pwPolicyURLButtonTitle}
set allowPasswordChange to allowPasswordChange as boolean
-- Change button text to better reflect behaviour when allowPasswordChange is set to false
if allowPasswordChange is true
tell application "System Events" to display dialog pwPolicy with icon 2 buttons {"OK", pwPolicyURLButtonTitle}
else
tell application "System Events" to display dialog pwPolicy with icon 2 buttons {"Cancel", pwPolicyURLButtonTitle}
end if
-- If pwPolicyURLButtonTitle...
if button returned of the result is pwPolicyURLButtonTitle
-- If pwPolicyURLButton is not set, then open pwPolicyURLButtonURL in the default browser
Expand Down

0 comments on commit daa0884

Please sign in to comment.