查找并粘贴 Apple 脚本
Find and Paste Apple Script
我在下面找到了一个 AppleScript,它可以查找和替换...但是在这种情况下我不想替换为“401”,而是希望它替换为剪贴板上的内容。
所以我想输入类似的内容:set stringToReplace to keystroke "v" using command down
...但这不起作用(预期行尾等,但找到了标识符。)
代码如下:
on run {input, parameters}
set stringToFind to "404"
set stringToReplace to "401"
set theFile to choose file
set theContent to read theFile as «class utf8»
set {oldTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, stringToFind}
set ti to every text item of theContent
set AppleScript's text item delimiters to stringToReplace
set newContent to ti as string
set AppleScript's text item delimiters to oldTID
try
set fd to open for access theFile with write permission
set eof of fd to 0
write newContent to fd as «class utf8»
close access fd
on error
close access theFile
end try
return input
end run
解决了问题:
我需要做的就是在 set stringToReplace to
之后添加:the clipboard
on run {input, parameters}
set stringToFind to "404"
set stringToReplace to the clipboard
set theFile to choose file
set theContent to read theFile as «class utf8»
set {oldTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, stringToFind}
set ti to every text item of theContent
set AppleScript's text item delimiters to stringToReplace
set newContent to ti as string
set AppleScript's text item delimiters to oldTID
try
set fd to open for access theFile with write permission
set eof of fd to 0
write newContent to fd as «class utf8»
close access fd
on error
close access theFile
end try
return input
end run
我在下面找到了一个 AppleScript,它可以查找和替换...但是在这种情况下我不想替换为“401”,而是希望它替换为剪贴板上的内容。
所以我想输入类似的内容:set stringToReplace to keystroke "v" using command down
...但这不起作用(预期行尾等,但找到了标识符。)
代码如下:
on run {input, parameters}
set stringToFind to "404"
set stringToReplace to "401"
set theFile to choose file
set theContent to read theFile as «class utf8»
set {oldTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, stringToFind}
set ti to every text item of theContent
set AppleScript's text item delimiters to stringToReplace
set newContent to ti as string
set AppleScript's text item delimiters to oldTID
try
set fd to open for access theFile with write permission
set eof of fd to 0
write newContent to fd as «class utf8»
close access fd
on error
close access theFile
end try
return input
end run
解决了问题:
我需要做的就是在 set stringToReplace to
the clipboard
on run {input, parameters}
set stringToFind to "404"
set stringToReplace to the clipboard
set theFile to choose file
set theContent to read theFile as «class utf8»
set {oldTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, stringToFind}
set ti to every text item of theContent
set AppleScript's text item delimiters to stringToReplace
set newContent to ti as string
set AppleScript's text item delimiters to oldTID
try
set fd to open for access theFile with write permission
set eof of fd to 0
write newContent to fd as «class utf8»
close access fd
on error
close access theFile
end try
return input
end run