Applescript ไม่ทำงานบน High Sierra


0

ฉันสร้างรหัสแอปพลิเคชันเพื่อช่วยเปลี่ยนชื่อรูปภาพจำนวนมากและสร้างไฟล์ข้อความที่มีชื่อไฟล์และส่วนข้อมูลเพื่อให้เราสามารถส่งออกไปยังทีมอื่นเพื่อตั้งโปรแกรมเป็นอีเมล

รหัสทำงานได้อย่างสมบูรณ์แบบเมื่อฉันอยู่ใน Sierra แต่ตั้งแต่ฉันอัปเดตเป็น High-Sierra มันไม่ได้เปลี่ยนชื่อไฟล์ทั้งหมด โดยปกติแล้วอีเมลของเราอาจมีภาพ 4-20 ภาพที่ต้องเปลี่ยนชื่อ แต่ด้วย macOS ใหม่สคริปต์จะเปลี่ยนชื่อภาพ 2 ภาพและหยุดด้วยข้อความนี้

**error "Can’t get item 1 of {}." number -1728 from item 1 of {}**

นี่คือรหัส แต่ปัญหาเกิดขึ้นที่

set h to (item 1 of dimensions) --/ dpi_to_dpmm -- works out pixel height as mm

หากใครสามารถช่วยฉันขอขอบคุณมัน

    --PopUp Window to select folder of files needing to be renamed
set iFolder to (choose folder with prompt "Select Folder")
--Sets folder path to readable location
set fPath to POSIX path of iFolder
--Sets folder path parent folder
set pPath to POSIX path of ((iFolder as text) & "::")
--removes listing invisible files
set fContent to list folder iFolder as list without invisibles
--seperates file name from extension
set text item delimiters to "."


tell application "Finder"
    --set gPath to fPath as string
    set all_files to every item of (iFolder) as list

    -- Multiple Selections
    set theDeviceList to {"Regular", "Luxury", "Holiday"}

    set theDevice to (choose from list theDeviceList with title "Device Selection" with prompt "Choose a Naming Convention:")

    set choices to the result as string
    -- Multiple Selections

    -- Begin Normal Email
    if choices is equal to "Regular" then
        -- Normal Email

        set new_FirstnameCol1 to "row"
        set new_LastNameCol1 to "-1col1image-responsive-image"

        set new_FirstnameCol2 to "row"
        set new_LastNameCol2 to "-2col2images-responsive2-image"

        set new_FirstnameCol3 to "row"
        set new_LastNameCol3 to "-3col3images-responsive2-image"

        --**Counter Begins
        --1 Column Counter
        set col1 to 1
        --2 Column Counter
        set col2 to 0
        --3 Column Counter
        set col3 to 0
        --Keeps count of all grouped columns
        set columnCounter to 0
        --Numbering convention to file name
        set universalCounter to 0
        set oopsCounter to 0
        --**Counter Ends

        repeat with i from 1 to the count of all_files
            --using our index, we select the appropriate file from our list
            set universalCounter to i - columnCounter - oopsCounter
            set this_file to item i of all_files
            set file_name_count to text items of (get name of this_file)
            set {itemName, itemExtension} to {name, name extension} of this_file

            set source_file to item i of fContent
            set fName to do shell script "basename " & quoted form of POSIX path of source_file
            set wholePath to fPath & source_file

            --Creates text file
            try
                do shell script "touch " & pPath & "results.txt"
            end try

            --Check to see if there is a file extension
            if itemExtension is "" then
                -- "" means there is no file-extension present.
                set file_extension to ""
            else
                --yup, we are currently processing a file that has a file-extension
                --we have to re-add the original file-extension after changing the name of the file!
                set file_extension to "." & itemExtension
            end if

            --Gets the height and width of each file
            set dimensions to paragraphs of (do shell script "sips -g pixelHeight -g pixelWidth " & quoted form of wholePath & " | grep pixel | cut -d':' -f 2 | cut -d ' ' -f 2")
            set h to (item 1 of dimensions) --/ dpi_to_dpmm -- works out pixel height as mm
            set w to (item 2 of dimensions) --/ dpi_to_dpmm -- works out pixel width as mm


            if w is greater than or equal to 548 then
                --Col1
                set the name of this_file to new_FirstnameCol1 & universalCounter & new_LastNameCol1 & col1 & file_extension as string
                set txtName to new_FirstnameCol1 & universalCounter & new_LastNameCol1 & col1 as string


            else if w is greater than or equal to 288 then
                --Col2
                set col2 to col2 + 1
                set the name of this_file to new_FirstnameCol2 & universalCounter & new_LastNameCol2 & col2 & file_extension as string
                set txtName to new_FirstnameCol2 & universalCounter & new_LastNameCol2 & col2 as string
                if col2 > 1 then
                    set col2 to 0

                else
                    set columnCounter to columnCounter + 1
                end if
            else if w is greater than or equal to 101 then
                --Column 3
                set col3 to col3 + 1
                set the name of this_file to new_FirstnameCol3 & universalCounter & new_LastNameCol3 & col3 & file_extension as string
                set txtName to new_FirstnameCol3 & universalCounter & new_LastNameCol3 & col3 as string
                if col3 > 2 then
                    set col3 to 0

                else
                    set columnCounter to columnCounter + 1
                end if
            else if w is greater than or equal to 1 then
                --Oops
                set the name of this_file to new_FirstnameCol1 & new_LastNameCol1 & "_oops" & i & file_extension as string
                set txtName to new_FirstnameCol1 & new_LastNameCol1 & "_oops" & i as string

                set oopsCounter to oopsCounter + 1
            else
                --Oops
                set the name of this_file to new_FirstnameCol1 & new_LastNameCol1 & "_oops" & i & file_extension as string
                set txtName to new_FirstnameCol1 & new_LastNameCol1 & "_oops" & i as string

                set oopsCounter to oopsCounter + 1
            end if
            do shell script "echo '" & txtName & " " & w & " x " & h & "' >> " & pPath & "results.txt"

        end repeat
        --End Normal Email

        --** remove this section if adding more options
    else
        display alert "Something Went Wrong"
        --** remove this section if adding more options
        end if
end tell
โดยการใช้ไซต์ของเรา หมายความว่าคุณได้อ่านและทำความเข้าใจนโยบายคุกกี้และนโยบายความเป็นส่วนตัวของเราแล้ว
Licensed under cc by-sa 3.0 with attribution required.