applescriptmacos-mojavesystem-preferences

How to make a script that doesn't ask permission every time it's opened


I have made an apple script that takes pictures of people using PhotoBooth. However, every time I open it, it asks for permission to use PhotoBooth instead of instantly taking a photo. I have already set the [Security & Privacy > Privacy > Automation > Allow Script to use PhotoBooth] but it still prompts me every time to allow PhotoBooth. Is there any way to fix this without downloading anything or changing my script? Thanks!


Solution

  • Is your script saved as an applet? While 10.14 remembers previous user-granted permissions, it will re-prompt every time the script changes. Traditional AppleScript applets implement a basic persistence mechanism that saves the current state of the script's top-level variables upon quitting. Discussion here:

    https://forum.latenightsw.com/t/mojave-and-applescript-applets/1563/13

    One quick trick for avoiding any persistent state:

    script MyScript
        -- original code goes here…
    end script
    
    on run
        local tempScript
        copy MyScript to tempScript
        run tempScript
    end run
    

    If you do need to save state (e.g. user preferences) between runs, then you'll either need to code sign the applet or else use an alternate mechanism (e.g. NSUserDefaults via AppleScript-ObjC).