在applescript中显示数字单元格范围

时间:2018-06-30 00:10:41

标签: numbers applescript

所以我有一段用applescript编写的代码,是我从互联网上获得的,它完全符合我想要的...但是我喜欢玩...

所以我需要为我做的与众不同的事情很多,为了这个特定代码的连续性,我不确定是否应该将所有内容都保留在一个线程中……也许不是,但是这里

所以首先,我希望能够使用显示警报来显示通过的实际范围(也许只是为了用户确认...,但我也希望能够一次在Apple脚本中对其进行操作。我已经捕获了。

不确定我应该如何发布代码,所以我将从按原样发布开始,也许有人会指示如何正确发布代码,这样它就不会尝试运行。

出于描述目的,此代码将在Numbers中选择的单元格范围内,用公式结果替换公式 -非常擅长使用now()函数创建时间戳记-

但是我并不总是知道我要使用哪个范围,并且当前选定的单元格并不总是在范围开始的地方等等。

所以我认为,一旦applescript拥有了它,便能够操纵该范围会很酷...我遇到的第一个绊脚石是我不知道如何显示所选范围。因此,由于我无法弄清楚如何显示它,所以我当然无法验证我是否正确操作了它。

在代码中,您将看到许多显示命令,其中一个显示为'&f&'或其他内容。...sr是包含所选范围的变量。所以我以为用sr代替f和bob是你的叔叔...发生了什么让我感到惊讶...代码运行得很好...除了我从来没有看到显示对话框...当然当我尝试将以前的经验与我以为其他语言有不同的变量类型,我认为它需要一个不同的“标识符”,因此显示将知道如何处理它……但是无论我尝试了什么,我所得到的只是语法错误或代码运行而没有显示对话框或显示警报...。

希望我在没有TMI的情况下提供了足够的详细信息 请提供有关如何在不同情况下处理不同变量的信息。 我昨晚一整夜都在尝试Google搜索,但从未找到任何使用display来显示范围结果的示例。

--Select cells in Numbers 3, run; Reads value of cell and replaces formula with text
--https://discussions.apple.com/thread/6497878
--SGIII, v1, 201408

try

tell application "Numbers" to tell front document to tell active sheet

    tell (first table whose selection range's class is range)
        set sr to selection range
        #           set sr to range "a:a"
        set rs to sr
        set f to "not empty"
        set tgtCellNames to {"A1", "A16", "A31", "A46", "A61"}
        set tgtCellNames to {"A1", "A16", "A31", "A46", "A61"}
        #           display dialog "Replacing ' " & tgtCellNames & " ' with " default answer " not so fast " with title "Formula 2 text replace step 1"


        #           display dialog "Replacing ' " & f & " ' with " default answer " not so fast " with title "Formula 2 text replace step 1"
        #           set f to display dialog "Find this in selected cells in Numbers " default answer "" with title "Find-Replace Step 1" buttons {"Cancel", "Next"}
        #           set f to result's text returned
        set f to " b1:b9 "
        #           if f = "" then display dialog "Did you really want to replace null with something that will appear between each pair of letters?" buttons {"Cancel", "Yes"} with title "Find and Replace"

        #           display dialog "Replacing ' " & range & " ' with "not so fast " with title "Formula 2 Text replace step "
        #           display dialog "Replacing ' " & f & " ' with " default answer " not so fast " with title "Formula 2 text replace step 1"
        #           set r to result's text returned
        set r to ""

        tell sr to repeat with i from 1 to count cells
            try
                set oVal to (cell i's value) as text
                if oVal is not "missing value" then
                    set nVal to my oVal
                    set value of cell i to nVal
                    # display dialog "hello world ' " & f & "   " & oVal & "  With " & nVal & "  " with title "Formula 2 text step 2"
                    display dialog "Found empty cell: " & (name of cell i of selection range)
                end if
            end try
        end repeat

    end tell
end tell
on error 
display dialog "Did you select cells?" buttons {"cancel"} with title "Oops!"
end try
--handlers

to findReplace(tt, f, r)
set oTID to AppleScript's text item delimiters
considering case
    set AppleScript's text item delimiters to f
    set lst to tt's text items
    set AppleScript's text item delimiters to r
    set tt to lst as string
end considering
set AppleScript's text item delimiters to oTID
return tt
end findReplace

0 个答案:

没有答案