スクリプトをサポートしていないアプリ (TimeFactory2) の動作を自動化するために、この AppleScript アプリを作成しています。それで、私はそれを使って UI スクリプトを作成することになります。私が使用するために、アプリの複数のインスタンスを同時に実行したいので、.app をコピーし、すべてのコピーを起動します (ポイントは、マルチスレッドを利用することです。各インスタンスはコンピューターのコアを使用します-アプリは非常に CPU を集中的に使用しますが、マルチスレッドはサポートしていません)。だから私は最初にこのコードで終わった(フランス語のコメントでごめんなさい):
tell application "TimeFactory2 Demo"
activate
end tell
tell application "System Events"
tell process "TimeFactory2 Demo"
repeat with extension in extensions_list
-- pomme-O pour sélectionner un fichier à ajouter
repeat until window "Open" exists
keystroke "o" using {command down}
end repeat
-- pomme-shift-g pour entrer un path de fichier
keystroke "g" using {shift down, command down}
-- on copie dans le clipboard le path du fichier à séléctionner
tell application "Finder" to set the clipboard to (audio_file_path & extension)
-- on colle dans la box
keystroke "v" using {command down}
-- enter enter
keystroke return
keystroke return
end repeat
-- dans le cas où la dernière selection de fichier n'aurait rien donné, on fait deux fois escape pour sortir des fenêtre de sélection de fichier
key code 53
key code 53
end tell
end tell
...これは、TF2 のインスタンスが 1 つしか実行されていない場合にうまく機能します。ただし、2 つ以上のインスタンスを実行すると、すべてが壊れます。徹底的なテストの後、何らかの理由で次の行について理解しました:
repeat until window "Open" exists
...スクリプトは、開いているウィンドウが存在するかどうかを判断できなくなり(存在する場合でも)、command-o キーストロークを何度もエミュレートします。プロセスの名前がアプリのすべてのインスタンスで同じであるという事実からすべてが来たと思ったので、コード
tell process "TimeFactory2 Demo"
システムにはあいまいでした。次に、あいまいさを取り除く方法を検索し、各プロセスをその unix ID で特定しようとしました (ここでは、uid が 629 のインスタンスの例を示します)。
set TF2_process_list to every process whose unix id is 629
set TF2_process to item 1 of TF2_process_list
tell (process TF2_process)
repeat until window "Open" exists
keystroke "o" using {command down}
delay 2
end repeat
end tell
次のエラーが発生しました:
error "System Events error : impossible to render {} as integer type." number -1700 from {} to integer
...そして、私はそこで立ち往生しています。この問題の解決策を求めてインターネットをかなり調べましたが、まだわかりません。誰でも解決策を見ますか?それとも、この問題を回避するスクリプト全体への別のアプローチでしょうか?