我想知道是否可以转义控制字符,并在AppleScript中插入一串文本。例如,AppleScript是否支持十六进制转义代码?如果是这样的话,是怎么做的?(我在谷歌上搜索了一下,但一无所获,如果这是个微不足道的问题,我很抱歉。)
上下文
对于某些任务,我想编写一个^D (\x04)到iTerm2,以指示stdin的结束。下面是我的剧本的骨架:
#!/usr/bin/osascript
tell application "iTerm"
create window with default profile
tell the current window
tell the current session
# write some text -- launch an interactive program
# write some text to stdin, typically from the clipboard
##### PROBLEM HERE
# close stdin -- write text ^D? How to achieve this?
end tell
end tell
end tell我不想使用击键代替,因为这将需要额外的特权。有更好的方法不逃避^D吗?欢迎任何建议。
发布于 2014-12-20 20:40:15
在MacOSX10.5及更高版本上,使用“字符id",例如:
set ctrlD to character id 4数字应该对应于字符的Unicode代码点值,对于字符0-127,与其ASCII值相同。
在10.4.11及更早版本中,使用"ascii字符“,例如:
set ctrlD to ascii character 4数字应该是字符的ASCII值。苹果从MacOSX10.5开始就不再推荐这种形式了,但从OSX10.10.1开始仍然有效。
然后,您应该能够像对待任何其他字符串一样对待"ctrlD“。还没有在iTerm中进行过专门的尝试,但是如果问题是如何将不可打印的字符输入到AppleScript字符串中,这就是方法。
发布于 2014-12-20 09:16:04
要发送命令,可以:
tell application "System Events" to key code 2 using {shift down, Control down}https://stackoverflow.com/questions/27573593
复制相似问题