ios 有没有一种方法可以使用脚本编写自动键入列表?

z5btuh9x  于 2023-06-05  发布在  iOS
关注(0)|答案(2)|浏览(124)

我需要一个代码,这将键入每个项目一个接一个
例如:myList {“Apple Watch”,“iMac”,“iPhone”,“MacBook Pro”}
我想要的结果类型为:
Apple Watch
iMac
iPhone
MacBook Pro

我试过编写代码,但由于知识不足,无法做到

我的代码:

set theList to {"Apple Watch", "iMac", "iPhone", "MacBook Pro"}
length of theList
tell application "System Events"
    set condition to 0
    set varName to item 1 of theList
    repeat until condition = length of theList
        keystroke of varName
        keystroke return
        set condition to condition + 1
        set varName to (item 1) + condition
    end repeat
end tell
dy2hfwbg

dy2hfwbg1#

此脚本提供您所需的功能。我添加了第一个tell块,以便您可以按原样运行这个脚本,并看到它在TextEdit中工作,但它会将文本键入到任何接受文本输入的应用程序中。

tell application "TextEdit"
    activate
    make new document
end tell

tell application "System Events"
    
    set theList to {"Apple Watch", "iMac", "iPhone", "MacBook Pro"}
    
    repeat with theItem in theList
        set stringLength to the count of theItem
        
        set theString to characters 1 thru stringLength of theItem
        
        repeat with nextCharacter in theString
            keystroke nextCharacter
            delay 0.2
        end repeat
        
        keystroke return
        keystroke return
        
    end repeat
    
end tell
sh7euo9m

sh7euo9m2#

tell application "System Events"
        set varX to 1
        set condition to 0
        repeat until condition = length of theList
            set varName to item varX of theList
            keystroke of varName
            delay 0.2
            keystroke return
            set varX to varX + 1
            set condition to condition + 1
        end repeat
    end tell
end tell

相关问题