我想创建一个AppleScript,它:
从Latex文件中剪切一些文本(我正在使用TexShop)
提示用户输入新文件名
将用文本/subfile{certain_path}
我相信我可以通过调用set theData to (the clipboard as text)
从剪贴板中获取内容。
我知道如何用display dialog
和text returned of
等向用户询问文件名。
我现在知道如何通过从document 1
获取路径,然后在其上调用container of
来在同一目录中创建一个新文件。
而且我知道如何写入该文件。
我遇到的问题是:
如果我想让AppleScript运行cut而不是用户,我是否必须使用GUI脚本命令tell application "System Events" to keystroke "x" using {command down}
,因为TexShop词典中没有“ cut text”命令?
如何告诉AppleScript在剪切文本的确切位置写subfile{etc.}
?如何告诉AppleScript将文本准确地粘贴到我想要的新文件的一部分中?
基本概念:
假定文本已被剪切(?):
tell application "Finder"/"TexShop" to set thisWord to get clipboard as text
或者,使用AppleScript以某种方式“调用” CMD-X:
tell application "System Events" to keystroke "x" using {command down}
获取文件名:
set response to display dialog "Filename: " default answer ""
set fileName to get text of response & ".tex"`
获取容器路径
tell application "TexShop" to set thePath to get path of document 1
tell application "Finder" to set parentPath to get container of thePath
写"\subfile{" & parentPath & fileName & "}"
确切地是从哪里剪切出来的?怎么样???
制作新文件:
tell application "Finder" to set newFile to ¬
make new file at parentPath with properties {name:fileName}
写入文件:
set preamble to "
\documentclass{article}
\begin{document}
\begin{English}"
& thisWord &
"\end{English}
\begin{Swedish}
\end{Swedish}
\end{document}"
set openFile to open newFile with write permission
write preamble to openFile
按上述方式组合字符串对我来说很好,但是在我已经写完以上内容之后知道如何将Word写入特定位置也很有趣。
我知道这里有多个问题,但是如果您能帮助我,我将无法表达我的感激之情。这个问题困扰了我太久了,我只是想知道如何使这种自动化发挥作用。谢谢。