Applescript无法构建错误的语法错误

时间:2017-12-12 03:26:10

标签: bash macos syntax applescript

好的,我现在已经把这个问题倾倒了20次了,这让我感到困惑。我正在为Citra Emu的“金丝雀”版本编写一个非官方的更新程序。起初一切都顺利完成,应用程序运行良好,但它严重依赖带有硬编码路径的Bash脚本。我想让它们更具动态性,以便在多台机器/ macOS版本之间轻松安装和维护。

我认为最好的选择是将剩余的代码转换为Applescript,并且只在必要时通过do shell script进行Bash调用。现在大部分都有效。该程序构建正常,但它似乎由于单独的语法错误而失败,并且在此处看不见。这是代码(请原谅这个混乱。):

tell application "Citra" to display dialog "Update Citra to the newest build?" buttons {"Update", "Open Current Build"} default button "Update" with title "Citra Canary Updater" with icon path to resource "Citra.icns" in bundle (path to application "Citra")

if the button returned of the result is "Update" then
  tell application "System Events" to write "DoUpdate" to file (path to resource "update/ShoudUpdate" in bundle (path to application "Citra"))
  else
  tell application "System Events" to write "NotUpdate" to file (path to resource "update/ShouldUpdate" in bundle (path to application "Citra"))
end if

set ShouldUpdate to read file (path to resource "update/ShouldUpdate" in bundle (path to application "Citra"))

if ShouldUpdate is equal to "DoUpdate" then
  tell application "System Events" to write "true" to file (path to resource "update/UpdateIsRunning" in bundle (path to application "Citra"))
  tell application "System Events" to write "0" to file (path to resource "update/UpdatePercentage" in bundle (path to application "Citra"))
  tell application "System Events" to write "Downloading Build Archive" to file (path to resource "update/UpdateAction" in bundle (path to application "Citra"))
  tell application "System Events" to write "Pinging update server..." to file (path to resource "update/UpdateStatus" in bundle (path to application "Citra"))
  tell application "Citra Canary Updater"
      activate
  end tell
  else
  tell application "System Events"
      do shell script ("~/Library/Application\\ Support/Citra/canary/citra-qt.app/Contents/MacOS/citra-qt-bin")
  end tell
end if
set UpdateServerIP to "github.com"  
try
   set ping to (do shell script "ping -c 1" & UpdateServerIP)
   tell application "System Events" to write "yes" to file (path to resource "update/ServerIsAvailable" in bundle (path to application "Citra"))
on error
   tell application "System Events" to write "no" to file (path to resource "update/ServerIsAvailable" in bundle (path to application "Citra"))
end try
set ServerIsAvailable to read file (path to resource "update/ServerIsAvailable" in bundle (path to application "Citra"))

if ServerIsAvailable is equal to "yes" then
  tell application "System Events" to write "10" to file (path to  resource "update/UpdatePercentage" in bundle (path to application "Citra"))  
  tell application "System Events" to write "Retrieving files..." to file (path to resource "update/UpdateStatus" in bundle (path to application "Citra"))
  tell application "System Events"
   do shell script ("/usr/local/bin/wget -O citra-osx.tgz $(curl -s https://api.github.com/repos/citra-emu/citra-canary/releases/latest | grep 'browser_' | cut -d\" -f4 | grep osx | grep tar.gz)")
  end tell
  else
  tell application "System Events" to write "false" to file (path to resource "update/UpdateIsRunning" in bundle (path to application "Citra"))
  tell application "System Events" to write "0" to file (path to resource "update/UpdatePercentage" in bundle (path to application "Citra"))
  tell application "System Events" to write "NULL" to file (path to resource "update/UpdateAction" in bundle (path to application "Citra"))
  tell application "System Events" to write "NULL" to file (path to resource "update/UpdateStatus" in bundle (path to application "Citra"))
  tell application "Citra" to display dialog "The update server is not available. Please try again later." buttons {"Open Current Build", "Close"} default button "Open Current Build" with title "Citra Canary Updater" with icon caution
  if the button returned of the result is "Open Current Build" then
    tell application "System Events"
        do shell script ("~/Library/Application\\ Support/Citra/canary/citra-qt.app/Contents/MacOS/citra-qt-bin")
    end tell
  end if
end if

tell application "System Events"
    if exists file ((path to home folder from user domain as text) & "citra-osx.tgz") then
      tell application "System Events" to write "35" to file (path to resource "update/UpdatePercentage" in bundle (path to application "Citra"))
      tell application "System Events" to write "Installing New Build" to file (path to resource "update/UpdateAction" in bundle (path to application "Citra"))
      tell application "System Events" to write "Moving files to temp directory..." to file (path to resource "updates/UpdateStatus" in bundle (path to application "Citra"))
      tell application "System Events"
          do shell script ("mv ~/citra-osx.tgz ~/Library/Application\\ Support/Citra/citra-osx.tgz")
      end tell
      tell application "System Events" to write "40" to file (path to resource "update/UpdatePercentage" in bundle (path to application "Citra"))
      tell application "System Events" to write "Wiping old build..." to file (path to resource "update/UpdateStatus" in bundle (path to application "Citra"))
      tell application "System Events"
          do shell script ("cd ~/Library/Application\\ Support/Citra/; rm -R canary/;")
      end tell
      tell application "System Events" to write "55" to file (path to resource "update/UpdatePercentage" in bundle (path to application "Citra"))
      tell application "System Events" to write "Extracting build archive..." to file (path to resource "update/UpdateStatus" in bundle (path to application "Citra"))
      tell application "System Events"
          do shell script ("cd ~/Library/Application\\ Support/Citra/; tar xzvf citra-osx.tgz;")
      end tell
      tell application "System Events" to write "65" to file (path to resource "update/UpdatePercentage" in bundle (path to application "Citra"))
      tell application "System Events" to write "Deleting build archive..." to file (path to resource "update/UpdateStatus" in bundle (path to application "Citra"))
      tell application "System Events"
          do shell script ("cd ~/Library/Application\\ Support/Citra/; rm citra-osz.tgz;")
      end tell
      tell application "System Events" to write "80" to file (path to resource "update/UpdatePercentage" in bundle (path to application "Citra"))
      tell application "System Events" to write "Moving files to permanent directory..." to file (path to resource "update/UpdateStatus" in bundle (path to application "Citra"))
      tell application "System Events"
          do shell script ("cd ~/Library/Application\\ Support/Citra/; mv citra-osx* canary/;")
      end tell
      tell application "System Events" to write "100" to file (path to resource "update/UpdatePercentage" in bundle (path to application "Citra"))
      tell application "System Events" to write "Done" to file (path to resource "update/UpdateAction" in bundle (path to application "Citra"))
  delay 3
      tell application "System Events" to write "false" to file (path to resource "update/UpdateIsRunning" in bundle (path to application "Citra"))
      tell application "System Events" to write "0" to file (path to resource "update/UpdatePercentage" in bundle (path to application "Citra"))
      tell application "System Events" to write "NULL" to file (path to resource "update/UpdateAction" in bundle (path to application "Citra"))
      tell application "System Events" to write "NULL" to file (path to resource "update/UpdateStatus" in bundle (path to application "Citra"))
      tell application "System Events"
          do shell script ("~/Library/Application\\ Support/Citra/canary/citra-qt.app/Contents/MacOS/citra-qt-bin & disown")
      end tell
      else
      tell application "System Events" to write "false" to file (path to resource "update/UpdateIsRunning" in bundle (path to application "Citra"))
      tell application "System Events" to write "0" to file (path to resource "update/UpdatePercentage" in bundle (path to application "Citra"))
      tell application "System Events" to write "NULL" to file (path to resource "update/UpdateAction" in bundle (path to application "Citra"))
      tell application "System Events" to write "NULL" to file (path to resource "update/UpdateStatus" in bundle (path to application "Citra"))
      tell application "Citra" to display dialog "Your system is not supported by the latest build. Please try again later." buttons {"Open Current Build", "Close"} default button "Open Current Build" with title "Citra Canary Updater" with icon caution
      if the button returned of the result is "Open Current Build" then
        tell application "System Events"
             do shell script ("~/Library/Application\\ Support/Citra/canary/citra-qt.app/Contents/MacOS/citra-qt-bin")
        end tell
      end if
    end if
end tell

现在我意识到这是处理进度条的一种相当多余和草率的方式,但请保持你的判断,因为手头的问题更加有趣。尝试直接运行此脚本时,它返回:

  

“运行Shell脚本”操作遇到错误:“1533:1534:语法错误:预期”“”但发现未知令牌。( - 2741)“

我会坦率地说,我没有丝毫知道 1533:1534:部分是什么,我从来没有能够分辨出这部分Applescript错误代码代表什么鉴于它的结构类似于指向发生错误的行和列的C调试器,但显然这个脚本中肯定没有1500行。

这似乎是一个标准的语法错误,但是我已经阅读了整个脚本,就像我说的那样,20次,我只是无法找到导致此语法错误的原因。它在脚本编辑器中构建良好,但尝试运行它会导致上述错误,与保存和运行应用程序包或Bash脚本相同。

更重要的是,Xcode中突出显示的Bash语法或脚本编辑器中突出显示的Applescript语法都没有引起我的注意。事实上,根据他们的语法突出显示一切都很好。

如果有人可以帮我弄清楚这个脚本的哪个部分被破坏了,我们将不胜感激。在这一点上,我正试图解决这个问题。

0 个答案:

没有答案