简体   繁体   中英

make an application ask for password applescript

I'm trying to write an AppleScript Code which makes Firefox ask me for a password when I open it. This is what I got, but somehow it doesn't work:

on activate
display dialog "Please enter your password" buttons {"Cancel", "Okay"} default answer "" default button 2
set x to text returned
if x is "Password" then
    tell application "Firefox"
        activate
        reopen
    end tell
else
    say "please try again"
end if
end activate

I also need to know where to save the Script, when it is correct. Thanks a lot!

There was an error in the set x to text returned . It needs to know what dialog you're referring to. See below.

on activate
set passwordRequest to display dialog "Please enter your password" buttons {"Cancel", "Okay"} default answer "" default button 2
set x to text returned of passwordRequest

if x is "Password" then
    tell application "Firefox"
        activate
        reopen
    end tell
else
    say "please try again"
end if
end activate

Heres how paste this in ur script editor then save as whatever the name you want but also save as a application when you do that u can change the app log to what ever you want then run the

on run
    set defaultanswer to display dialog "Please enter a passphrase to use this script." default answer "" with icon stop buttons {"Cancel", "Continue"} default button "Continue" with hidden answer
    set x to text returned of defaultanswer

    if x is "ANY PASSWORD U WANT" then
        tell application "ANY APPLICATION U WANT"
            activate
            reopen
        end tell
    else
        say "please try again"
    end if
end run

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM