通过 Applescript 调用 Skype API 最多触发 100 个安全授权请求
我正在开发一个Applescript,它没有什么花哨的功能,只是询问Skype有多少联系人在线...但是,当脚本被执行几次,而Skype没有运行,最后运行时,Skype会打开无数的对话框窗口Skype API 安全请求,询问是否允许 Applescript 使用 Skype。
不幸的是我找不到这个问题的解决方案。 如果您有想法,我将非常感谢您的帮助!
提前致谢! Julian
这里提到的脚本:
set onlineFriendsCount to 0
set resultArray to {}
-- define a string replace method
on ReplaceText(theString, findStr, replaceStr)
将 current_Delimiters 设置为 AppleScript 的文本项分隔符 将 AppleScript 的文本项分隔符设置为 findStr 将 sList 设置为 theString 的每个文本项 将AppleScript 的文本项定界符设置为replaceStr 将 newString 设置为 sList 作为字符串 将 AppleScript 的文本项分隔符设置为 current_Delimiters 返回新字符串 end ReplaceText
on countString(myText, myDelimiter)
将 {oldDelimiters, AppleScript 的文本项分隔符} 设置为 {AppleScript 的文本项分隔符, myDelimiter} 将 myCounter 设置为(计算 myText 的文本项数)- 1 将 AppleScript 的文本项分隔符设置为 oldDelimiters
return myCounter
end countString
tell application "System Events"
将 active_flag 设置为(进程名称)包含“Skype” 结束告诉 如果是 active_flag 则
告诉应用程序“Skype”
——首先找出在线“朋友”的数量(这是 Skype 的行话) 设置组发送命令“SEARCH GROUPS HARDWIRED”脚本名称“getType” 将 groupList 设置为组的单词
将 groupCount 设置为 groupList 中的项目数
重复 i 从 2 到 groupCount 将组设置为组列表的项目 i
设置组类型以发送命令“GET GROUP”&组& “TYPE”脚本名称“getType” 如果 groupType 包含“ONLINE”则 设置 onlineFriends 发送命令“GET GROUP” &组& “USERS”脚本名称“getType” --将 onlineFriends 设置为 onlineFriends 的单词
-- setting the new string delimiter for chunking the resulting list
set oldDelimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to ","
set onlineFriendsList to every text item of onlineFriends
set AppleScript's text item delimiters to oldDelimiters
set AppleScript's text item delimiters to ","
set onlineFriendsCount to (number of items in onlineFriendsList)
-- this is a little workaround to get the correct number of online contacts:
if onlineFriendsCount = 1 then
set resultArray to resultArray & 0
else
set resultArray to resultArray & onlineFriendsCount
end if
exit repeat
end if 结束重复
——获取心情信息 设置心情消息发送命令“GET PROFILE MOOD_TEXT”脚本名称“getType” 将心情字符串设置为我的 ReplaceText(moodMessage, "PROFILE MOOD_TEXT ", "") 将心情字符串设置为我的 ReplaceText(moodStrings, ",", "") 将 resultArray 设置为 resultArray &心情弦乐 -- 获取在线状态 设置 onlineStatus 发送命令(“GET USERSTATUS”)脚本名称“getType” 将 onlineStatus 设置为我的 ReplaceText(onlineStatus, "USERSTATUS ", "") 将 resultArray 设置为 resultArray &在线状态 -- 获取活跃聊天数量 设置 activeChats 发送命令“SEARCH ACTIVECHATS”脚本名称“getType” 将 activeChats 设置为我的 countString(activeChats, "#") 将 resultArray 设置为 resultArray &活跃聊天 -- 检查是否有正在进行的通话 设置 activeCalls 发送命令“SEARCH ACTIVECALLS”脚本名称“getType” 将 callNum 设置为 activeCalls 的单词数 如果callNum > 1 那么 将 resultArray 设置为 resultArray &真的 别的 将 resultArray 设置为 resultArray &错误的 end 如果
返回 resultArray
end 告诉
else
将 resultArray 设置为 {0, "", "OFFLINE", 0, false}
end if
I am working on an Applescript, which does nothing fancy but asking Skype how many contacts are online... However, when the script was executed several times, while Skype was not running, and finally is running, then Skype opens uncountable dialog windows with a Skype API Security Request, asking whether or not to allow the Applescript to use Skype.
Unfortunately I can't find a solution for this problem.
In case you have an idea, I would appreciate your help very much!
Thanks in advance!
Julian
Here the mentioned script:
set onlineFriendsCount to 0
set resultArray to {}
-- define a string replace method
on ReplaceText(theString, findStr, replaceStr)
set current_Delimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to findStr
set sList to every text item of theString
set AppleScript's text item delimiters to replaceStr
set newString to sList as string
set AppleScript's text item delimiters to current_Delimiters
return newString
end ReplaceText
on countString(myText, myDelimiter)
set {oldDelimiters, AppleScript's text item delimiters} to {AppleScript's text item delimiters, myDelimiter}
set myCounter to (count text items of myText) - 1
set AppleScript's text item delimiters to oldDelimiters
return myCounter
end countString
tell application "System Events"
set the active_flag to (name of processes) contains "Skype"
end tell
if active_flag then
tell application "Skype"
-- find out first the number of online "friends" (this is skype jargon)
set groups to send command "SEARCH GROUPS HARDWIRED" script name "getType"
set groupList to words of groups
set the groupCount to the number of items in groupList
repeat with i from 2 to the groupCount
set group to item i of groupList
set groupType to send command "GET GROUP " & group & " TYPE" script name "getType"
if groupType contains "ONLINE" then
set onlineFriends to send command "GET GROUP " & group & " USERS" script name "getType"
--set onlineFriends to words of onlineFriends
-- setting the new string delimiter for chunking the resulting list
set oldDelimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to ","
set onlineFriendsList to every text item of onlineFriends
set AppleScript's text item delimiters to oldDelimiters
set AppleScript's text item delimiters to ","
set onlineFriendsCount to (number of items in onlineFriendsList)
-- this is a little workaround to get the correct number of online contacts:
if onlineFriendsCount = 1 then
set resultArray to resultArray & 0
else
set resultArray to resultArray & onlineFriendsCount
end if
exit repeat
end if
end repeat
-- get the mood message
set moodMessage to send command "GET PROFILE MOOD_TEXT" script name "getType"
set moodStrings to my ReplaceText(moodMessage, "PROFILE MOOD_TEXT ", "")
set moodStrings to my ReplaceText(moodStrings, ",", "")
set resultArray to resultArray & moodStrings
-- get the online status
set onlineStatus to send command ("GET USERSTATUS") script name "getType"
set onlineStatus to my ReplaceText(onlineStatus, "USERSTATUS ", "")
set resultArray to resultArray & onlineStatus
-- get the number of active chats
set activeChats to send command "SEARCH ACTIVECHATS" script name "getType"
set activeChats to my countString(activeChats, "#")
set resultArray to resultArray & activeChats
-- check if there are ongoing calls
set activeCalls to send command "SEARCH ACTIVECALLS" script name "getType"
set callNum to count of words of activeCalls
if callNum > 1 then
set resultArray to resultArray & true
else
set resultArray to resultArray & false
end if
return resultArray
end tell
else
set resultArray to {0, "", "OFFLINE", 0, false}
end if
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
安全请求与您的脚本没有任何关系。当执行任何脚本或 Skype API 客户端时,它应该弹出。请仅选择第一个选项“允许此应用程序使用 Skype”,您将不会再看到此弹出窗口。
詹诺
The security request doesn't have anything to do with your script. It should pop-up when executing any scripts or Skype API clients. Please just select the first option "allow this application to use Skype" and you will not see this pop-up any more.
Janno