AppleScript to Check If Chrome Extension Is Installed

applescriptgoogle-chrome

Using AppleScript, I need to check if Adblock Plus (ABP) is installed in the Chrome Browser.
After numerous attempts at trying to figure out how, I have come to the conclusion that it would be relatively easy to check if the ABP "firstRun.html" exists.

Or is there a more reliable script to check if this specific extension is installed?

Here is my script, however it always returns true. Please Help.

if checkIfABPInstalled() is true then
    log "FOUND"
else
    log "NOT FOUND"
end if


on checkIfABPInstalled()
    try
        tell application "Google Chrome"
            if ("chrome-extension://cfhdojbkjhnklbpkdaibdccddilifddb/firstRun.html") exists then
                return true
            else
                return false
            end if
        end tell
    on error
        return false
    end try
end checkIfABPInstalled

Best Answer

Google Chrome's AppleScript Dictionary doesn't have a direct method to check for extensions, so you need to test for the Adblock Plus extension in a different way.

If the Adblock Plus extension is installed, then the adblockplus.js file will exist within the "$HOME/Library/Application Support/Google/Chrome/Default/Extensions/ directory structure. So I'd test for its existence and the example AppleScript code below does that.

set fileExists to do shell script "find \"$HOME/Library/Application Support/Google/Chrome/Default/Extensions\" -iname adblockplus.js 2>/dev/null"

if fileExists is not "" then
    display dialog "Adblock Plus is installed." buttons {"OK"} default button 1
else
    display dialog "Adblock Plus is not installed." buttons {"OK"} default button 1 with icon caution
end if