文件被复制到特定文件夹并重命名为 x.txt 如何打开 x.txt 并将“X:”粘贴到
编辑:regulus6633 制作了一个比我下面的大纲好得多的脚本,如果您的模板文件不完全为空,它就可以完美工作(我认为这最初导致了错误)。谢谢!
该脚本应该 (1) 将 x.txt 复制到特定文件夹,将其重命名为 new_name,(2) 打开它,(3) 将“new_name”全部大写粘贴,以及 (4) 插入“:”,然后返回&返回。第一部分有效,但我无法弄清楚 (2)、(3) 和 (4)。到目前为止我编写的代码粘贴在下面。
tell application "Finder"
display dialog "new_name_dialogue" default answer " "
set new_name to (text returned of result)
set Selected_Finder_Item to (folder of the front window) as text
duplicate file "Q:x:7:n7:GTD scripting:template folder:x.txt" to "Q:X:7:SI:SIAG1"
set Path_Of_X to "Q:X:7:SI:SIAG1:" & "x.txt" as string
set name of file Path_Of_X to (new_name as text) & ".txt"
#[something that let's me open the file is needed here]
#[something that pastes "new_name" & ":" in ALL CAPS]
#[something that inserts two lineshifts]
end tell
EDIT: regulus6633 has made a script that's a lot better than my outline below, it works perfectly IF you're template file isn't completely empty (I think this caused an error originally). Thanks!
This script is supposed to (1) copy a x.txt to a specific folder rename it to new_name, (2) open it, (3) paste "new_name" in all caps, and (4) insert ":" followed by return & return. The first part is working, but I'm having trouble figuring out (2), (3) and (4). The code I've written so far is pasted below.
tell application "Finder"
display dialog "new_name_dialogue" default answer " "
set new_name to (text returned of result)
set Selected_Finder_Item to (folder of the front window) as text
duplicate file "Q:x:7:n7:GTD scripting:template folder:x.txt" to "Q:X:7:SI:SIAG1"
set Path_Of_X to "Q:X:7:SI:SIAG1:" & "x.txt" as string
set name of file Path_Of_X to (new_name as text) & ".txt"
#[something that let's me open the file is needed here]
#[something that pastes "new_name" & ":" in ALL CAPS]
#[something that inserts two lineshifts]
end tell
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一般来说,由于您正在处理 txt 文件,因此不需要在应用程序中“打开”该文件并粘贴文本。我们可以直接从 applescript 读取和写入文本文件。因此,我们从模板文件中读取文本,添加我们想要的任何文本,然后将新文本写入新文件。如果您想打开并查看新文件,则可以在之后执行此操作。我在代码的“TextEdit”部分中做到了这一点。
您可以在脚本末尾看到我有子例程来写入文本文件并将文件名更改为大写字母。那么请尝试以下操作...
In general since you're dealing with a txt file, you do not need to "open" the file in an application and paste in text. We can read and write to text files directly from applescript. As such we read in the text from the template file, add whatever text we want to that, and then write the new text to a new file. If you then want to open and view the new file you can do that after. I did that in the "TextEdit" section of the code.
You can see at the end of the script I have subroutines to write a text file and also to change the file name to CAPS. So try the following...
有一个非常好的第三方脚本添加(Satimage OSAX),您可以将其用于类似这样的事情(只有在您下载了脚本添加内容时才有效)...
There is a really good third party scripting addition (Satimage OSAX) that you can use for things just like this (this will only work if you've downloaded the scripting addition)...