2013-05-03 22 views
0

我將一個文件複製到一個新文件夾,然後重命名它。接下來,我想打開它: -從重複文件捕獲編輯文件名

set myNewFile to duplicate myFile to myNewLocation 
set the name of myNewFile to myNewFileName 
open myNewFile 

第2行以上的工作,但打開命令不起作用,因爲它無法找到該文件,因爲我給它改名。我想要做的事,如: -

open myNewLocation & myNewFileName 

myNewLocation是一個有效的路徑,myNewFileName只是一個字符串,我有我需要的所有數據,但我不能工作了如何從構建一個有效的可用路徑兩個項目。

另外我也許可以在複製文件的同時更改名稱,然後將其保存到myNewFile中。我已經試過: -

set myNewFile to duplicate myFile to myNewLocation with name myNewFileName 

set myNewFile to duplicate myFile to myNewLocation with properties {name:myNewFileName} 

既不工作。

回答

0

嘗試:

tell application "Finder" to set myFile to file "Mac OS X:Users:JD:Desktop:testStart.txt" 
set myNewLocation to (path to desktop as text) 
set myNewFileName to "testEnd.txt" 

set myNewFile to duplicate myFile to myNewLocation 

set the name of myNewFile to myNewFileName 

tell application "Finder" to open file (myNewLocation & myNewFileName) 
+0

這個答案的關鍵是確定myNewFileName作爲取景器的文件。您也可以使用:打開myNewLocation的文件myNewFileName – markhunte 2013-05-03 20:51:00

+0

@ markhunte的版本直接與我的腳本一起工作(我的路徑是一個別名),或者如果我按照adayzdone的工作版本將路徑轉換爲文本。謝謝,都。 – marcovanbostin 2013-05-07 14:37:24