Applescript 在 Big Sur 中莫名其妙地失败了

问题描述

我一直在使用 TextExpander 来运行这个脚本,最近它在更新到 Big Sur 后开始失败。认为它与 TextExpander 相关,我创建了一个类似的快捷方式来在 BetterTouchTool 中运行它,但遇到了同样的问题。它不会抛出一个可见的错误,它只是在完成时播放错误音并且不输出任何内容。奇怪的是,当我从脚本编辑器运行它时,它运行得很好。只有当它被另一个进程调用时它才会失败。

脚本的基本思想是在对话框中输入原始数字并在最前面的应用程序中输出格式化的时间码。例如输入“207”输出“01:00:02:07”

我已经搜索代码,但找不到可能导致错误的原因,因为这都是非常基本的文本操作。任何想法都会非常有帮助。

tell application "System Events"
--Set process that called text expander aside so it can be returned to the front
set frontProcessName to name of item 1 of (processes whose frontmost is true)

-- Get the raw numbers from the user
set raw_timecode to text returned of (display dialog "Timecode" default answer "")

-- Set the default variables
set user_timecode to "" as string
set rt_length to the length of raw_timecode

--Check to see if the TC field is blank
if raw_timecode = "" then
    set raw_timecode to "01000000"
end if

--Parse the user supplied numbers and replace any "." with "00"
repeat with n from 1 to rt_length
    if character n of raw_timecode = "." then
        set user_timecode to user_timecode & "00" as text
    else
        set user_timecode to user_timecode & character n of raw_timecode as text
    end if
    
end repeat

--Set to 00:00:00:00 if only digit is 0 
if user_timecode = "0" then
    set base_timecode to "00000000"
else
    set base_timecode to "01000000"
end if

set x to the length of user_timecode


-- Trim extra digits off base timecode
if x = 8 and user_timecode ≠ "0" then
    set raw_timecode to user_timecode as string
else
    repeat while (length of base_timecode) + (length of user_timecode) > 8
        try
            set base_timecode to characters 1 thru -(x + 1) of base_timecode as string
            set raw_timecode to base_timecode & user_timecode as string
        on error
            display dialog "Invalid timecode"
            error number -128
        end try
    end repeat
end if
set new_timecode to characters 1 thru 2 of raw_timecode & ":" & characters 3 thru 4 of raw_timecode & ":" & characters 5 thru 6 of raw_timecode & ":" & characters 7 thru 8 of raw_timecode as text

end tell

-- Return the prevIoUs app that called text expander to the front
tell application frontProcessName to activate
delay 0.5

return new_timecode

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...