2013-02-26 36 views
1

我是新来的applescript。 我正在尝试创建一个Automator脚本应用程序,该应用程序在InDesign中打开批处理现有文件,查找并更改文件中的文本。 (我认为这将是复杂的一点,但它不是很容易) 我正在努力的是将这些文件保存在另一个位置,但使用原始文件名,因为我需要保留原始文件。 我有一个脚本来指定一个路径和文件名,但我只需要指定路径并使用现有的文件名。这可能吗?如何指定文件路径但不是名称InDesign applescript

我尝试的代码是这样的:

tell application "Adobe InDesign CS5.5" 
save document 1 to "users:xxx:Desktop:" 
close document 1 
end tell 

这似乎并不为,我不是指定一个文件名的原因的工作,但我不想!有没有调用原始文件名的方法? 我假设必须有这样做的方式,因为我看不到特定于某个特定文件的脚本。

我的下一步就是再通过更换文件名如的最后一位的文件重命名: xxx_xxx_M6.indd到xxx_xxx_M7.indd 我知道如何在另一个脚本做到这一点,但如果它可以在上面进行部分会很棒。

回答

0

如果你想使用保存在原来的文件名,你可以从文件的属性把它和与路径结合起来,你要保存到,像这样:

set origName to the name of document 1 as string 
save document 1 to ("your:path:here:" & origName) 

编辑:如果您已经有自己的例程来替换后缀,您可以在将它传递给保存命令之前,在origName上执行这些操作。我会留下我的后缀替换下面,以防万一它有助于任何人。


至于你的问题的第二部分,关于替换后缀,这取决于你想要做什么。从你的例子我猜你想增加一个号码,你可以用下面的代码做:

set thePoint to the offset of "." in origName 
set firstPart to (characters 1 through (thePoint - 1) of origName) as string 
set fpLength to the length of firstPart 

set newSuffix to ((the last character of firstPart) as number) + 1 
set newName to (characters 1 through (fpLength - 1) of firstPart) & newSuffix ¬ 
    & ".indd" as string 

这需要从它的扩展名分隔文件名,通过增加最后一个字符创建一个新的后缀(强制为一个数字)的名称,然后将这个组合成一个完整的文件名,然后可以在save命令中使用它。

关键是拆分原始文件名,然后对零件执行操作。

现在,它目前有一些限制:除了一位数字以外的任何后缀使事情变得更加复杂(尽管不是不可能),并且假定运行该脚本的任何人在Finder的首选项中启用了“显示所有文件扩展名”这可以解决,虽然)。

结束语一切行动给了我们这样的:

tell application "Adobe InDesign CS5.5" 
    set origName to the name of document 1 as string 

    set thePoint to the offset of "." in origName 
    set firstPart to (characters 1 through (thePoint - 1) of origName) as string 
    set fpLength to the length of firstPart 

    set newSuffix to ((the last character of firstPart) as number) + 1 
    set newName to (characters 1 through (fpLength - 1) of firstPart) ¬ 
     & newSuffix & ".indd" as string 

    save document 1 to ("your:path:here:" & newName) 
end tell 

如果你能提供有关你要使用的后缀一些更多的信息我很高兴来更新我的答案。

0

InDesign文档有3个您可能感兴趣的属性:
name:“xxx_xxx_M6。INDD”
file path:文件的 “Macintosh HD:sourceFolder:”
full name:文件的 “Macintosh HD:sourceFolder:xxx_xxx_M6.indd”

因此,为了节省(&接近)在桌面上打开的文件,同名称,你可以这样做:

tell application "Adobe InDesign CS5.5" 
    save document 1 to "users:xxx:Desktop:" & name of document 1 
    close document 1 
end tell 
相关问题