iT邦幫忙

0

apple script 語法問題請教

  • 分享至 

  • xImage

請教
下列語法可以在 apple automate 執行, 但要儲存成sh檔案的時候會出現下列訊息, 語法錯誤, 要如何修正? 謝謝
https://ithelp.ithome.com.tw/upload/images/20241010/20003705P0EH6CAiGc.png

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

2
jeffeux
iT邦新手 4 級 ‧ 2024-10-11 14:00:55
  1. AppleScript 不是 shell script
  2. 問 ChatGPT 應該就可以有自動給你案例的功能了

您甚至可以結合兩者,請 ChatGPT 把這段翻譯為 AppleScript

然後如果您是要用 .sh 檔案,請直接用文字編輯器存檔為例如 myscript.sh,然後 terminal 開起來輸入

bash myscript.sh

就好。

以下是 ChatGPT 提供的 AppleScript 翻譯


請幫我把這段 shell script 翻譯為 AppleScript,我看了一下基本沒問題,跟我學的 AppleScript 運作模式是一致的

find /Users/anderson/Downloads/downloadKdR7g194738/ -ctime +1d -mtime +1d -iname '*.*'

ChatGPT 說:
這段 Shell Script 的功能是查找在指定目錄中創建和修改時間都超過一天的檔案。下面是將其轉換為 AppleScript 的範例:

set targetFolder to POSIX file "/Users/anderson/Downloads/downloadKdR7g194738/" as alias
set theFiles to {}

tell application "Finder"
    set fileList to every file of targetFolder
    repeat with aFile in fileList
        set fileCreationDate to (creation date of aFile)
        set fileModificationDate to (modification date of aFile)
        
        if (fileCreationDate < (current date) - (1 * days)) and (fileModificationDate < (current date) - (1 * days)) then
            set end of theFiles to (aFile as text)
        end if
    end repeat
end tell

return theFiles

這段 AppleScript 將遍歷指定的資料夾,並收集創建和修改時間都超過一天的檔案。你可以根據需要進行調整!

我要發表回答

立即登入回答