不允许 AppleScript 应用程序发送击键
AppleScript Application is not allowed to send keystrokes
我用 AppleScript 制作了一个名为 FRIDAY 的应用程序。当我告诉它 'open chrome' 时,它会打开 google chrome,这是在脚本编辑器和脚本编辑器之外工作的。我也可以告诉它 'open a new tab' 并使用击键打开一个新选项卡:
-- this boolean is the reason this script keeps runing
set condition to false
say "Welcome sir"
set commands to {"what is todays date", "what time is it", "what is the time", "what day is it", "what month is it", "which month is it", "friday you up", "friday", "friday you tere", "you there", "empty the trash", "take out the trash", "clean up", "new tab", "next tab", "back", "take a nap", "go to sleep", "take a rest", "wake up", "copy the link", "paste the link", "give me list of running apps", "open a folder", "open chrome", "open youtube", "open atom", "quit atom", "goodbye FRIDAY_AI", "okay thanks", "okay thank you", "thanks", "thank you", "good night", "good morning", "morning", "night", "hey friday"}
repeat until condition is true
try
tell application "SpeechRecognitionServer"
set FRIDAY_AI to listen continuously for commands with identifier "mine" with section title "FRIDAY's Commands"
end tell
-- full date
set todays_date to date string of (current date)
-- day
set todays_day to weekday of (current date) as string
-- time
set t to time string of (current date)
-- month
set m to month of (current date) as string
-- time and day
if FRIDAY_AI = "what is todays date" then
say todays_date
end if
if FRIDAY_AI = "what time is it" then
say t
end if
if FRIDAY_AI = "what is the time" then
say t
end if
if FRIDAY_AI = "what day is it" then
say todays_day
end if
if FRIDAY_AI = "what month is it" then
say m
end if
if FRIDAY_AI = "which month is it" then
say m
end if
-- end of time and day
-- Clear trash --
if FRIDAY_AI = "empty the trash" then
tell application "Finder"
empty the trash
end tell
end if
-- FRIDAY --
if FRIDAY_AI = "friday" then
say "yes"
end if
if FRIDAY_AI = "friday you up" then
say "for you sir, alllways"
end if
if FRIDAY_AI = "friday you there" then
say "yes"
end if
if FRIDAY_AI = "you there" then
say "yes"
end if
if FRIDAY_AI = "hey friday" then
say "hey sir, waht can I do for you"
end if
-- END OF FRIDAY --
if FRIDAY_AI = "take out the trash" then
tell application "Finder"
empty the trash
end tell
end if
-- end of clear trash --
-- QUITS EVERY APPLICATION --
if FRIDAY_AI = "clean up" then
say "cleaning up"
delay 2
say "goodbye sir"
tell application "System Events" to set the visible of every process to true
set white_list to {"Finder"}
try
tell application "Finder"
set process_list to the name of every process whose visible is true
end tell
repeat with i from 1 to (number of items in process_list)
set this_process to item i of the process_list
if this_process is not in white_list then
tell application this_process
quit
end tell
end if
end repeat
on error
tell the current application to display dialog "An error has occurred!" & return & "This script will now quit" buttons {"Quit"} default button 1 with icon 0
end try
end if
-------------------------------------
-- SWITCH BETWEEN TABS TABS --
if FRIDAY_AI = "new tab" then
tell application "System Events"
key code 17 using {command down}
end tell
end if
--next tab --
if FRIDAY_AI = "next tab" then
tell application "System Events"
key code 48 using {control down}
end tell
end if
-- priveus tab --
if FRIDAY_AI = "back" then
tell application "System Events"
key code 48 using {shift down, control down}
end tell
end if
-- END OF SWITCH BETWEEN TABS --
-- launches screen saver
if FRIDAY_AI = "take a nap" then
try
tell application id "com.apple.ScreenSaver.Engine" to launch
end try
end if
if FRIDAY_AI = "go to sleep" then
try
tell application id "com.apple.ScreenSaver.Engine" to launch
end try
end if
if FRIDAY_AI = "take a rest" then
try
tell application id "com.apple.ScreenSaver.Engine" to launch
end try
end if
if FRIDAY_AI = "wake up" then
tell application "System Events"
key code 49
end tell
end if
-- END OF SCREEN SAVER --
if FRIDAY_AI = "give me list of running apps" then
tell application "System Events"
key code 53 using {command down, option down}
end tell
end if
-- copy url --
if FRIDAY_AI = "copy the link" then
tell application "System Events"
key code 37 using {command down}
delay 0.5
key code 8 using {command down}
end tell
end if
-- paste url --
if FRIDAY_AI = "paste the link" then
tell application "System Events"
key code 37 using {command down}
delay 0.5
key code 9 using {command down}
keystroke return
end tell
end if
if FRIDAY_AI = "open a folder" then
log FRIDAY_AI
tell application "Finder"
activate
make new Finder window
set target of front window to home
end tell
end if
if FRIDAY_AI = "open chrome" then
tell application "Google Chrome"
log FRIDAY_AI
say "Opening Google Chrome sir"
activate
end tell
end if
(* if FRIDAY_AI = "open atom" then
tell application "Atom"
log FRIDAY_AI
say "opening Atom"
activate
end tell
end if
if FRIDAY_AI = "quit atom" then
log FRIDAY_AI
tell application "Atom" to quit
end if *)
if FRIDAY_AI = "goodbye FRIDAY_AI" then
log FRIDAY_AI
say "goodbye sir"
-- quit = exist the program completely--
-- Stop the script- -
exit repeat
end if
if FRIDAY_AI = "open youtube" then
log FRIDAY_AI
tell application "Google Chrome"
activate
open location "https://www.youtube.com/"
end tell
end if
-- JUST PERSONAL COMMENTARY --
if FRIDAY_AI = "thanks" then
log FRIDAY_AI
say "I am glad, I could be of help sir"
end if
if FRIDAY_AI = "okay thanks" then
log FRIDAY_AI
say "I am glad, I could be of help sir"
end if
if FRIDAY_AI = "thank you" then
log FRIDAY_AI
say "You're welcome sir"
end if
if FRIDAY_AI = "okay thank you" then
log FRIDAY_AI
say "You're welcome sir"
end if
if FRIDAY_AI = "good night" then
log FRIDAY_AI
say "Good night sir"
end if
if FRIDAY_AI = "night" then
log FRIDAY_AI
say "Good night sir"
end if
if FRIDAY_AI = "good morning" then
log FRIDAY_AI
say "Good morning sir"
end if
if FRIDAY_AI = "morning" then
log FRIDAY_AI
say "morning sir"
end if
-- END OF PERSONAL COMMENTARY --
-- if an error occurs, it goes back and keep repeating
on error
set condition to false
end try
end repeat
现在,上面的代码仅在我在脚本编辑器中 运行 FRIDAY 时有效,但当我将 FRIDAY 另存为应用程序并 运行 它时它不起作用。
脚本编辑器和我的应用程序 (FRIDAY) 具有可访问性,事实上 FRIDAY 具有完整的磁盘可访问性。但它仍然无法发送击键。
我一直收到这个错误:
System Events got an error: FRIDAY is not allowed to send keystrokes.
辅助功能:
全盘访问:
自动化:
如果你能帮我解决这个问题,我将不胜感激,谢谢!
我在更新到 macOS 10.15 Catalina 时遇到了类似的问题。我转到系统偏好设置 -> 安全和隐私 -> 辅助功能,在这里我删除了我的应用程序,然后再次添加它。在此之后,一切正常。
我还发现,虽然它被要求允许您的脚本访问系统事件,但如果您的脚本名称中有 spaces,它不会添加到安全和隐私中。在我用下划线替换 space 之前,我一直在努力解决这个问题。然后它被添加到这里并且从那以后工作得很好。
您可以在辅助功能设置中启用鼠标键并使用击键 87。这就是我的自动答题器的工作方式。
**
这对我有用:
**
转到系统偏好设置 -> 安全和隐私 -> 辅助功能
并赋予 iterm2
权限
我来晚了一点,但这对我有用:
转到系统偏好设置 → 安全和隐私 → 隐私 → 辅助功能 → 允许以下应用程序控制您的计算机。 → 选中“Automator”应用程序。
https://i.stack.imgur.com/WkWEy.png
我用 AppleScript 制作了一个名为 FRIDAY 的应用程序。当我告诉它 'open chrome' 时,它会打开 google chrome,这是在脚本编辑器和脚本编辑器之外工作的。我也可以告诉它 'open a new tab' 并使用击键打开一个新选项卡:
-- this boolean is the reason this script keeps runing
set condition to false
say "Welcome sir"
set commands to {"what is todays date", "what time is it", "what is the time", "what day is it", "what month is it", "which month is it", "friday you up", "friday", "friday you tere", "you there", "empty the trash", "take out the trash", "clean up", "new tab", "next tab", "back", "take a nap", "go to sleep", "take a rest", "wake up", "copy the link", "paste the link", "give me list of running apps", "open a folder", "open chrome", "open youtube", "open atom", "quit atom", "goodbye FRIDAY_AI", "okay thanks", "okay thank you", "thanks", "thank you", "good night", "good morning", "morning", "night", "hey friday"}
repeat until condition is true
try
tell application "SpeechRecognitionServer"
set FRIDAY_AI to listen continuously for commands with identifier "mine" with section title "FRIDAY's Commands"
end tell
-- full date
set todays_date to date string of (current date)
-- day
set todays_day to weekday of (current date) as string
-- time
set t to time string of (current date)
-- month
set m to month of (current date) as string
-- time and day
if FRIDAY_AI = "what is todays date" then
say todays_date
end if
if FRIDAY_AI = "what time is it" then
say t
end if
if FRIDAY_AI = "what is the time" then
say t
end if
if FRIDAY_AI = "what day is it" then
say todays_day
end if
if FRIDAY_AI = "what month is it" then
say m
end if
if FRIDAY_AI = "which month is it" then
say m
end if
-- end of time and day
-- Clear trash --
if FRIDAY_AI = "empty the trash" then
tell application "Finder"
empty the trash
end tell
end if
-- FRIDAY --
if FRIDAY_AI = "friday" then
say "yes"
end if
if FRIDAY_AI = "friday you up" then
say "for you sir, alllways"
end if
if FRIDAY_AI = "friday you there" then
say "yes"
end if
if FRIDAY_AI = "you there" then
say "yes"
end if
if FRIDAY_AI = "hey friday" then
say "hey sir, waht can I do for you"
end if
-- END OF FRIDAY --
if FRIDAY_AI = "take out the trash" then
tell application "Finder"
empty the trash
end tell
end if
-- end of clear trash --
-- QUITS EVERY APPLICATION --
if FRIDAY_AI = "clean up" then
say "cleaning up"
delay 2
say "goodbye sir"
tell application "System Events" to set the visible of every process to true
set white_list to {"Finder"}
try
tell application "Finder"
set process_list to the name of every process whose visible is true
end tell
repeat with i from 1 to (number of items in process_list)
set this_process to item i of the process_list
if this_process is not in white_list then
tell application this_process
quit
end tell
end if
end repeat
on error
tell the current application to display dialog "An error has occurred!" & return & "This script will now quit" buttons {"Quit"} default button 1 with icon 0
end try
end if
-------------------------------------
-- SWITCH BETWEEN TABS TABS --
if FRIDAY_AI = "new tab" then
tell application "System Events"
key code 17 using {command down}
end tell
end if
--next tab --
if FRIDAY_AI = "next tab" then
tell application "System Events"
key code 48 using {control down}
end tell
end if
-- priveus tab --
if FRIDAY_AI = "back" then
tell application "System Events"
key code 48 using {shift down, control down}
end tell
end if
-- END OF SWITCH BETWEEN TABS --
-- launches screen saver
if FRIDAY_AI = "take a nap" then
try
tell application id "com.apple.ScreenSaver.Engine" to launch
end try
end if
if FRIDAY_AI = "go to sleep" then
try
tell application id "com.apple.ScreenSaver.Engine" to launch
end try
end if
if FRIDAY_AI = "take a rest" then
try
tell application id "com.apple.ScreenSaver.Engine" to launch
end try
end if
if FRIDAY_AI = "wake up" then
tell application "System Events"
key code 49
end tell
end if
-- END OF SCREEN SAVER --
if FRIDAY_AI = "give me list of running apps" then
tell application "System Events"
key code 53 using {command down, option down}
end tell
end if
-- copy url --
if FRIDAY_AI = "copy the link" then
tell application "System Events"
key code 37 using {command down}
delay 0.5
key code 8 using {command down}
end tell
end if
-- paste url --
if FRIDAY_AI = "paste the link" then
tell application "System Events"
key code 37 using {command down}
delay 0.5
key code 9 using {command down}
keystroke return
end tell
end if
if FRIDAY_AI = "open a folder" then
log FRIDAY_AI
tell application "Finder"
activate
make new Finder window
set target of front window to home
end tell
end if
if FRIDAY_AI = "open chrome" then
tell application "Google Chrome"
log FRIDAY_AI
say "Opening Google Chrome sir"
activate
end tell
end if
(* if FRIDAY_AI = "open atom" then
tell application "Atom"
log FRIDAY_AI
say "opening Atom"
activate
end tell
end if
if FRIDAY_AI = "quit atom" then
log FRIDAY_AI
tell application "Atom" to quit
end if *)
if FRIDAY_AI = "goodbye FRIDAY_AI" then
log FRIDAY_AI
say "goodbye sir"
-- quit = exist the program completely--
-- Stop the script- -
exit repeat
end if
if FRIDAY_AI = "open youtube" then
log FRIDAY_AI
tell application "Google Chrome"
activate
open location "https://www.youtube.com/"
end tell
end if
-- JUST PERSONAL COMMENTARY --
if FRIDAY_AI = "thanks" then
log FRIDAY_AI
say "I am glad, I could be of help sir"
end if
if FRIDAY_AI = "okay thanks" then
log FRIDAY_AI
say "I am glad, I could be of help sir"
end if
if FRIDAY_AI = "thank you" then
log FRIDAY_AI
say "You're welcome sir"
end if
if FRIDAY_AI = "okay thank you" then
log FRIDAY_AI
say "You're welcome sir"
end if
if FRIDAY_AI = "good night" then
log FRIDAY_AI
say "Good night sir"
end if
if FRIDAY_AI = "night" then
log FRIDAY_AI
say "Good night sir"
end if
if FRIDAY_AI = "good morning" then
log FRIDAY_AI
say "Good morning sir"
end if
if FRIDAY_AI = "morning" then
log FRIDAY_AI
say "morning sir"
end if
-- END OF PERSONAL COMMENTARY --
-- if an error occurs, it goes back and keep repeating
on error
set condition to false
end try
end repeat
现在,上面的代码仅在我在脚本编辑器中 运行 FRIDAY 时有效,但当我将 FRIDAY 另存为应用程序并 运行 它时它不起作用。
脚本编辑器和我的应用程序 (FRIDAY) 具有可访问性,事实上 FRIDAY 具有完整的磁盘可访问性。但它仍然无法发送击键。
我一直收到这个错误:
System Events got an error: FRIDAY is not allowed to send keystrokes.
辅助功能:
如果你能帮我解决这个问题,我将不胜感激,谢谢!
我在更新到 macOS 10.15 Catalina 时遇到了类似的问题。我转到系统偏好设置 -> 安全和隐私 -> 辅助功能,在这里我删除了我的应用程序,然后再次添加它。在此之后,一切正常。
我还发现,虽然它被要求允许您的脚本访问系统事件,但如果您的脚本名称中有 spaces,它不会添加到安全和隐私中。在我用下划线替换 space 之前,我一直在努力解决这个问题。然后它被添加到这里并且从那以后工作得很好。
您可以在辅助功能设置中启用鼠标键并使用击键 87。这就是我的自动答题器的工作方式。
**
这对我有用:
**
转到系统偏好设置 -> 安全和隐私 -> 辅助功能 并赋予 iterm2
权限我来晚了一点,但这对我有用:
转到系统偏好设置 → 安全和隐私 → 隐私 → 辅助功能 → 允许以下应用程序控制您的计算机。 → 选中“Automator”应用程序。
https://i.stack.imgur.com/WkWEy.png