1

次のAppleScriptをドロップレットとして保存しています。このようなDMGファイルに保存されますhttp://dl.dropbox.com/u/1839051/TestDMG.dmg

問題は、テンプレートをドロップレットにドラッグして機能させることができる一方で、テンプレートをドロップレットにドラッグしようとすると、このアクションが不可能であることを示す取り消し線の付いた円の記号が表示されることです。何も起こらず、ファイルはコピーされません。

なぜ私がこの問題を抱えているのか、そしてそれをどのように修正できるのか、誰かが知っていますか?よろしくお願いします。

on open thefiles    
  set outputFolder to (path to application support folder from user domain as text) & "iWork:Pages:Templates:My Templates:"
  do shell script "/bin/mkdir -p " & quoted form of POSIX path of outputFolder

  tell application "Finder"
    duplicate thefiles to outputFolder
  end tell    
end open
4

2 に答える 2

1

ドロップレットを使用してユーザーにドロップレットにファイルをドラッグさせるのではなく、ユーザーがインストーラーをダブルクリックするだけで済むようにインストーラーを作成してみませんか? その方が簡単で、おそらく問題を回避できます。また、配送コードでエラー処理を行うのが賢明であるため、コードにエラー処理を追加しました。また、何が起こったのかをユーザーに伝えます。

注: コードにもエラーがありました。outputFolder は文字列です。Finder にはファイル指定子が必要です。文字列を指定子にするには、文字列パスの前に「ファイル」または「フォルダー」という単語を追加します。あなたのコードは機能しているかもしれませんが、それを記述する適切な方法は指定子を使用することです。他のアプリケーションは文字列パスを取らないかもしれませんが、それらはすべて指定子を取ります... したがって、文字列の代わりにそれらを使用する習慣を身につけてください。

try
    -- create the output folder if necessary
    set outputFolder to (path to application support folder from user domain as text) & "iWork:Pages:Templates:My Templates:"
    do shell script "/bin/mkdir -p " & quoted form of POSIX path of outputFolder

    -- find the templates on the dmg disk
    set myPath to path to me
    tell application "Finder"
        set myContainer to container of myPath
        set templateFiles to (files of myContainer whose name extension is "template") as alias list
    end tell

    -- copy the templates to the output folder
    -- NOTE: the script will error if any of the templates already exist
    -- therefore we use a repeat loop and duplicate each file separately with a try block
    -- around it to avoid errors in case some templates have already been installed.
    tell application "Finder"
        repeat with aTemplate in templateFiles
            try
                duplicate aTemplate to folder outputFolder
            end try
        end repeat
    end tell

    -- tell the user everything was OK
    tell me to activate
    display dialog "The templates were successfully installed! You may now use them in Pages." buttons {"OK"} default button 1 with title "Templates Installer" with icon note
on error
    tell me to activate
    display dialog "There was an error installing the templates. Please manually install them by copying them to the following folder." & return & return & (POSIX path of outputFolder) buttons {"OK"} default button 1 with title "Templates Installer"
end try
于 2010-08-12T12:21:50.043 に答える
1

これはパーミッションの問題のようで、できる人とできない人の違いは、実行している OS と関係があるのではないかと考えなければなりません。管理者として Mac OS 10.6 を実行していますが、DMG でアクションを実行できませんでした。しかし、両方のファイルを DMG からデスクトップにドラッグすると、アクションを実行できました。

プロジェクトをサポートするためにハード ドライブの特定の場所にファイルをインストールする必要がある場合は、提示されたセットアップではなく、インストーラー (およびそれに対応するアンインストーラー) を作成することをお勧めします。

于 2010-08-12T09:51:13.223 に答える