Как включить расширения в Chromium с помощью AppleScript - PullRequest
0 голосов
/ 10 января 2020

macOS Мохаве 10.14.6. Я пытаюсь запустить Chromium с установленными расширениями. Сначала я попробовал это

open /Applications/Chromium.app --args --enable-extensions

Но ничего не происходит. Я выяснил, что браузеры на основе Chromium хранят настройки расширения в файле, расположенном в ~ / Library / Application Support / [Имя браузера на основе Chromium] / Default / Secure Preferences. Поэтому я попытался заменить в файле указанную c строку, которая активирует расширения. И я написал некоторый код:

set HomeFolder to path to home folder as text

on findAndReplaceInFile(theFile, theSearchString, theReplacementString)
    set theFile to alias (theFile)
    set theContent to read theFile as «class utf8»
    set {oldTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, theSearchString}
    set ti to every text item of theContent
    set AppleScript's text item delimiters to theReplacementString
    set newContent to ti as string
    set AppleScript's text item delimiters to oldTID
    try
        set fd to open for access theFile with write permission
        set eof of fd to 0
        write newContent to fd as «class utf8»
        close access fd
    on error
        close access theFile
    end try
end findAndReplaceInFile

findAndReplaceInFile(HomeFolder & "Library:Application Support:Chromium:Default:Secure Preferences", "\"state\":0", "\"state\":1")
findAndReplaceInFile(HomeFolder & "Library:Application Support:Chromium:Default:Secure Preferences", "\"ack_prompt_count\":1", "\"ack_external\":true")
findAndReplaceInFile(HomeFolder & "Library:Application Support:Chromium:Default:Secure Preferences", "\"pending_on_installed_event_dispatch_info\":{\"previous_version\":\"\"},", "")
findAndReplaceInFile(HomeFolder & "Library:Application Support:Chromium:Default:Secure Preferences", "[\"\\u003Call_urls>\"]},\"commands\":{},\"content_settings\":[],\"creation_flags\":9,\"disable_reasons\":8192,\"external_first_run\":true,\"from_bookmark\":false,\"from_webstore\":true", "[\"\\u003Call_urls>\"]},\"commands\":{},\"content_settings\":[],\"creation_flags\":9,\"events\":[],\"from_bookmark\":false,\"from_webstore\":true,\"granted_permissions\":{\"api\":[\"nativeMessaging\"],\"manifest_permissions\":[],\"scriptable_host\":[\"\\u003Call_urls>\"]}")

Но больше ничего не происходит

Вскоре я нашел код, который позволяет вам включить javascript в Safari, автоматически нажимая некоторые кнопки

try
        tell application "Safari"
                activate
        end tell  
        tell application "System Events"
                tell process "Safari"
                        click menu item "Preferences…" of menu "Safari" of menu bar item "Safari" of menu bar 1
                        click button "Security" of tool bar 1 of window 1
                        click checkbox "Enable Java" of group 1 of group 1 of window "Security"
                        click button 1 of window "Security"
                end tell
        end tell
end try 

Как я понимаю, это может сработать, если есть действия с системными клавишами / (радио) кнопками / флажками. Моя цель - просто включить расширение, нажав кнопку включения в настройках Chromium (например, Снимок экрана) Снимок экрана

Что я могу сделать?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...