gpt4 book ai didi

error-handling - 邮件的 Applescript 错误

转载 作者:行者123 更新时间:2023-12-03 09:07:04 35 4
gpt4 key购买 nike

我做了这个快速的 Applescript 应用程序,它给了我一个错误,这里是编码:

set buyannounce to "AUTOMATIC SERVER EMAIL : BUY"
set transferannounce to "AUTOMATIC SERVER EMAIL : TRANSFER"
set signupannounce to "AUTOMATIC SERVER EMAIL : SIGNUP"
set sellannounce to "AUTOMATIC SERVER EMAIL : SELL"
set nowsignup to "0"
set announce to "AUTOMATIC SERVER EMAIL"


set ¬
currentSignups ¬
to the text returned ¬
of (display dialog ¬
¬
"How many current signups?" default answer "")


tell application "Mail"
set unreadMessages to (get every message of mailbox "INBOX" of account "Yahoo" whose read status is true)
repeat with eachMessage in unreadMessages

if announce is in (get content of eachMessage) then

if buyannounce is in (get content of eachMessage) then
--buy email
end if
if transferannounce is in (get content of eachMessage) then
--transfer email
end if
if signupannounce is in (get content of eachMessage) then
set nowsignup to nowsignup + 1
set eachMessageTrimmed to ((characters 33 thru -1 of (get content of eachMessage)) as string)
display dialog nowsignup
set filepath to POSIX path of "/Users/obleopold/Dropbox/Accounts.csv"
try
set command to "open " & quoted form of filepath
do shell script command
end try
delay 10
repeat currentSignups times
tell "System Events" to keystroke return
end repeat
repeat nowsignup times



tell "System Events"
keystroke eachMessageTrimmed --here is where I am getting the error
end tell

tell "System Events" to keystroke return
currentSignups = currentSignups + nowsignup
set nowsignup to "0"

end repeat
end if




if sellannounce is in (get content of eachMessage) then
--sell email
end if

end if
end repeat
end tell
end
end
end
end

最佳答案

我没有检查您的代码是否正常工作,但这是编写代码以避免问题的一种方法。您可以使用子程序。当你从一个“tell”代码块中调用一个子程序时,你需要在它前面加上“my”这个词。这告诉脚本子例程属于脚本而不是您正在告诉的应用程序。

请注意,您可以通过获取消息内容一次来优化您的代码。每次您“获取每个消息的内容”时,都会对性能产生影响......所以只做一次。另请注意,我在您的击键命令之间添加了一些延迟。通常你需要这些小的延迟来防止在你做这样的事情时出错。它使您的计算机有一点额外的时间来执行击键。

祝你好运。

set buyannounce to "AUTOMATIC SERVER EMAIL : BUY"
set transferannounce to "AUTOMATIC SERVER EMAIL : TRANSFER"
set signupannounce to "AUTOMATIC SERVER EMAIL : SIGNUP"
set sellannounce to "AUTOMATIC SERVER EMAIL : SELL"
set nowsignup to "0"
set announce to "AUTOMATIC SERVER EMAIL"

set currentSignups to the text returned of (display dialog "How many current signups?" default answer "")

tell application "Mail"
set unreadMessages to (get every message of mailbox "INBOX" of account "Yahoo" whose read status is true)

repeat with eachMessage in unreadMessages
set messageContent to content of eachMessage
if announce is in messageContent then

if buyannounce is in messageContent then
--buy email
end if

if transferannounce is in messageContent then
--transfer email
end if

if signupannounce is in messageContent then
set nowsignup to nowsignup + 1

set eachMessageTrimmed to my trimMessageText(messageContent)
display dialog nowsignup
my openFilePath(POSIX path of "/Users/obleopold/Dropbox/Accounts.csv")
delay 10
repeat currentSignups times
my keystrokeSomething(return)
delay 0.2
end repeat
repeat nowsignup times
my keystrokeSomething(eachMessageTrimmed)
delay 0.2
my keystrokeSomething(return)
delay 0.2
currentSignups = currentSignups + nowsignup
set nowsignup to "0"
end repeat
end if

if sellannounce is in messageContent then
--sell email
end if
end if
end repeat
end tell


(************* SUBROUTINES *****************)
on trimMessageText(messageText)
try
return text 33 thru -1 of messageText
on error
return messageText
end try
end trimMessageText

on keystrokeSomething(something)
tell application "System Events"
keystroke something
end tell
end keystrokeSomething

on openFilePath(filepath)
try
do shell script "open " & quoted form of filepath
end try
end openFilePath

另一种分离你的告诉 block 的方法是这样的。但在你的情况下,子程序似乎更容易。
tell application "Mail"
-- do something
end tell

set eachMessageTrimmed to text 33 thru -1 of messageText

tell application "System Events"
-- do something
end tell

do shell script "something"

tell application "Mail"
-- do something
end tell

关于error-handling - 邮件的 Applescript 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18420572/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com