0

I'm trying to run an Applescript that centers the window with focus. The shortcut works well, but when I try to use voice command with Siri a "System Event" error occurs, apparently Siri does not have access authorization.

Someone has already seen this problem.

Screenshot showing the error.

Translation of the error from Portuguese to English: I'm sorry, there was a problem. Shortcuts say: "System Events got a Error: Shortcuts is an assistive access no Allowed."

5
  • 1
    If you want help debugging code, then you need to include the code in your question so we can copy and paste it without having to manually type it. That said, do you have Shortcuts added to System Preferences > Security & Privacy > Privacy > Accessibility? (Desculpem o inglês pois não falo português.) Nov 9 '21 at 13:59
  • Thank you very much for your reply. I had already done this, I even put Siri there too. I'm sure there must be a solution, but so far I haven't been able to find it. Nov 10 '21 at 16:20
  • The code didn't fit here, many characters, but I don't think that's the problem. The code works if I use the button in the Shortcuts application or if I put it in the top bar. Nov 10 '21 at 16:21
  • 1
    RE: "The code didn't fit here, many characters" -- Just copy and paste it as text from Shortcuts as an edit to your question, not on your website as it mangles the code and I'm not going to waste time fixing what you already posted. -- RE: "but I don't think that's the problem. The code works if I use the button in the Shortcuts application or if I put it in the top bar." -- Doesn't matter what the problem is. What matters is being able to test it on my side to see what is what, and go from there. Nov 10 '21 at 16:36
0

on run {input, parameters} tell application "Finder" set screenSize to bounds of window of desktop set screenWidth to item 3 of screenSize set screenHeight to item 4 of screenSize end tell

tell application "System Events"
    tell dock preferences
        if screen edge is bottom then
            tell application "System Events" to tell process "Dock"
                set dockSize to size in list 1
                set dockHeight to item 2 of dockSize
                set screenHeight to (screenHeight - dockHeight)
            end tell
        else if screen edge is left then
            tell application "System Events" to tell process "Dock"
                set dockSize to size in list 1
                set dockHeight to item 1 of dockSize
                set screenWidth to (screenWidth + dockHeight)
            end tell
        else
            tell application "System Events" to tell process "Dock"
                set dockSize to size in list 1
                set dockHeight to item 1 of dockSize
                set screenWidth to (screenWidth - dockHeight)
            end tell
        end if
    end tell
    
    set screenHeight to (screenHeight + 22)
    set myFrontMost to name of first item of ¬
        (processes whose frontmost is true)
end tell

try
    tell application myFrontMost
        set windowSize to bounds of window 1
        set windowXl to item 1 of windowSize
        set windowYt to item 2 of windowSize
        set windowXr to item 3 of windowSize
        set windowYb to item 4 of windowSize
        
        set windowWidth to windowXr - windowXl
        set windowHeight to windowYb - windowYt
        
        if myFrontMost is "Terminal" then
            set bounds of window 1 to {¬
                round ((screenWidth - windowWidth) / 2) rounding as taught in school, ¬
                round ((screenHeight - windowHeight) / 2) rounding as taught in school, ¬
                round ((screenWidth + windowWidth) / 2) rounding as taught in school, ¬
                round ((screenHeight + windowHeight) / 2) rounding as taught in school}
        else
            set bounds of window 1 to {¬
                round ((screenWidth - windowWidth) / 2) rounding as taught in school, ¬
                round ((screenHeight - windowHeight) / 2) rounding as taught in school, ¬
                round ((screenWidth + windowWidth) / 2) rounding as taught in school, ¬
                round ((screenHeight + windowHeight) / 2) rounding as taught in school}
        end if
        
        set the result to bounds of window 1
        
    end tell
end try

return input

end run

1
  • The first time I tried to paste the code, the site accused me that I had exceeded the character limit. This time that didn't happen. I had also put the link to the original page where I got the code. Nov 12 '21 at 23:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .