2017-05-14 6 views
0

最近AppleScriptを使用し始めましたが、私のスクリプトを動作させることはできません。しかし、私は何の誤りもありません。スクリプトは実行され、何も起こりません。私のカスタムAppleScriptに関するいくつかの視点が必要です

tell application "Finder" 
set theWin to window 1 
set thePath to (POSIX path of (target of theWin as alias)) 
copy file "Macintosh HD:Users:thijmendam:Documents:NieuwBestandSource:Naamloos.pages" to thePath 
end tell 

私がしたいことは、ファイルNaamloos.pagesを現在開いているFinderウィンドウに移動することです。私はそれをフォルダにコピーしたい場合、これはうまく動作します。しかし、私がthePathを使うと、何も起こりません。例では 、次のスクリプトは動作しません:

'tell application "Finder" 
set theWin to window 1 
set thePath to (POSIX path of (target of theWin as alias)) 
copy file "Macintosh HD:Users:thijmendam:Documents:NieuwBestandSource:Naamloos.pages" to folder "this:is:a:destination:folder" 
end tell 

明らかにこれは私が達成したいものではありません。私はファイルをthePathにコピーする方法を知りません。誰か助けてくれますか?

乾杯!

答えて

0

あなたはPOSIXパスを使用しようとしているので、それはちょうどFinderでファイルをコピーするために、すべての適切なコマンドの

+1

のように相対パスを使用することをお勧めします唯一のHFSパス(コロン区切り)

は、スクリプトをポータブルにするために受け入れるあなたにたくさんありがとうございました!これはうまくいった。 –

+0

私はシェルコマンドを実行しようとしている場合は、Posixのパスは良いです – mcgrailm

+0

また、私はポップアップテキストボックスなどで指定する必要がある特定の名前にファイルの名前を変更することは可能ですか?それ? –

0

ファーストを伝えるここ

tell application "Finder" 
set afile to (choose file) as alias 
set theWin to window 1 
set thePath to (target of theWin as alias) 
copy file afile to folder thePath 

最後の例であるとされて削除しますduplicate

Finderはpath to documents folder

set documentsFolder to path to documents folder as text 

set newName to text returned of (display dialog "Enter a Name" default answer "" buttons {"Cancel", "OK"} default button 2) 

if newName does not end with ".pages" the set newName to newName & ".pages" 

tell application "Finder" 
    set theWin to window 1 
    set thePath to target of theWin as alias 
    set duplicatedFile to duplicate file (documentsFolder & "NieuwBestandSource:Naamloos.pages") to thePath 
    set name of duplicatedFile to newName 
end tell 
+0

ありがとうございます。完璧に動作します。また、ファイルを複製する前にダイアログボックスを使ってカスタム名を付ける方法も知っていますか? –

+0

私は答えを更新しました。 – vadian

+0

ありがとう:-) –

関連する問題