从 Applescript 中的变量中删除单词
Removing a word from a variable in Applescript
我是 Applescript 的新手,如果单词中包含“#”,我不知道如何从变量中删除该单词。
我的脚本出现这个错误 -> "Can’t make word into type integer." number -1700 from word to integer
到目前为止,这是我的脚本:
activate application "Grids"
delay 2
tell application "System Events"
keystroke "a" using command down
delay 0.25
keystroke "c" using command down
delay 0.25
set Description to the clipboard
if any word in Description contains "#" then delete that word
return Description
end tell
有什么指点吗?
干杯,
克里斯
要从剪贴板中取出文本,请使用 (clipboard as text)
。剪贴板几乎可以包含多种格式的任何内容,甚至可以包含多个对象,因此 as text
为您提供了一个可以使用的字符串。
注意:'Description' 似乎是某些现有 appleScript 'terminology' 的一部分,至少在 Mac 我在这里,所以我将您的标识符更改为 desc
这里:
activate application "Grids"
delay 2
tell application "System Events"
keystroke "a" using command down
delay 0.25
keystroke "c" using command down
delay 0.25
set desc to the clipboard as text
end tell
set out to {}
set tids to AppleScript's text item delimiters
set AppleScript's text item delimiters to " "
repeat with anItem in (text items of desc)
set str to (anItem as string)
if (str does not contain "#") then
set end of out to str
end if
end repeat
set outStr to out as string
set AppleScript's text item delimiters to tids
return outStr
此代码只是 returns 您要查找的文本。它不会重新插入修饰过的字符串,也不会做任何其他有趣的事情。
我假设您要告诉系统事件通过 cmd-v 粘贴它。 (粘贴前记得set the clipboard to outStr
!)
AppleScript's text item delimiters
允许使用 space (或您希望的任何其他标记)拆分和重新组合字符串。出于代码卫生的原因,明智的做法是在更改它之前存储它,然后在之后将其重置为原始值,如此处所示,否则在期望它具有默认值的脚本中可能会发生奇怪的事情。
我是 Applescript 的新手,如果单词中包含“#”,我不知道如何从变量中删除该单词。
我的脚本出现这个错误 -> "Can’t make word into type integer." number -1700 from word to integer
到目前为止,这是我的脚本:
activate application "Grids"
delay 2
tell application "System Events"
keystroke "a" using command down
delay 0.25
keystroke "c" using command down
delay 0.25
set Description to the clipboard
if any word in Description contains "#" then delete that word
return Description
end tell
有什么指点吗?
干杯, 克里斯
要从剪贴板中取出文本,请使用 (clipboard as text)
。剪贴板几乎可以包含多种格式的任何内容,甚至可以包含多个对象,因此 as text
为您提供了一个可以使用的字符串。
注意:'Description' 似乎是某些现有 appleScript 'terminology' 的一部分,至少在 Mac 我在这里,所以我将您的标识符更改为 desc
这里:
activate application "Grids"
delay 2
tell application "System Events"
keystroke "a" using command down
delay 0.25
keystroke "c" using command down
delay 0.25
set desc to the clipboard as text
end tell
set out to {}
set tids to AppleScript's text item delimiters
set AppleScript's text item delimiters to " "
repeat with anItem in (text items of desc)
set str to (anItem as string)
if (str does not contain "#") then
set end of out to str
end if
end repeat
set outStr to out as string
set AppleScript's text item delimiters to tids
return outStr
此代码只是 returns 您要查找的文本。它不会重新插入修饰过的字符串,也不会做任何其他有趣的事情。
我假设您要告诉系统事件通过 cmd-v 粘贴它。 (粘贴前记得set the clipboard to outStr
!)
AppleScript's text item delimiters
允许使用 space (或您希望的任何其他标记)拆分和重新组合字符串。出于代码卫生的原因,明智的做法是在更改它之前存储它,然后在之后将其重置为原始值,如此处所示,否则在期望它具有默认值的脚本中可能会发生奇怪的事情。