-1

私はプログラミング、特に AppleScript の初心者です。バレンタイン デーに iTunes から曲を再生し、Safari でフラッシュ アニメーション ファイルを開く簡単なスクリプトを作成しました。ScriptEditor でスクリプトを実行すると、すべてが希望どおりに機能しますが、スタンドアロン アプリケーションとしてエクスポートすると、フルスクリーン モードを有効にするコマンドで失敗します。システムイベントの問題だと思います。明確にするために、アプリケーションは最後まで機能しますが、キーストロークコマンドで警告音が聞こえ、ウィンドウはそのままです。

Yosemite を実行しており、完全に更新されています。

理想的には、Google Chrome でファイルを開いてプレゼンテーション モードを利用したいのですが、Chrome でファイルを開くことさえできません。

アドバイスをありがとう!コードは次のとおりです。

tell application "Finder"
  set visible of every process whose visible is true and name is not "Finder" to false
  close every window
end tell

set volume output volume 75

tell application "iTunes"
  set currentVolume to sound volume
    if player state is playing then
      stop
      back track
    end if
  play track "The Promise"
  set player position to 6
end tell

delay 4

tell application "Safari"
  activate
  if (count of windows) is 0 then -- Remove "if" statement if you don't want to make a new window if there is none
    make new window at front
  end if

open (POSIX path of (path to home folder)) & "/Desktop/beMine/beMine.swf"
  tell application "System Events"
    tell process "Safari" to keystroke "f" using {command down, control down}

  end tell
end tell
4

2 に答える 2

0

ほとんどの場合、スタンドアロン アプリケーションがシステム イベントを使用できるようにする必要があります。ある時点で、Script Editor でこれを行う必要がありました。スタンドアロン アプリでも同じことを行う必要があります。

このオプションは、[セキュリティとプライバシー]、[プライバシー]、[アクセシビリティ] の [システム環境設定] にあります。アプリのリストが表示されますが、あなたのアプリはおそらく [以下のアプリによるコンピューターの制御を許可する] のチェックなしでそこにリストされています。</p>

アプリをリストに追加するには、「+」ボタンを使用する必要がある場合があります。

この単純なスクリプトを使用して Safari を全画面表示できることを確認しました。アクセシビリティの下でアプリに許可が与えられている場合は機能し、許可されていない場合は黙って失敗します。

tell application "Safari"
    activate
end tell

tell application "System Events"
    tell process "Safari" to keystroke "f" using {command down, control down}
end tell

これは Mac OS X 10.10 の Yosemite です。Mac OS X の他のバージョンでは異なる場合があります。

于 2015-02-15T21:35:26.203 に答える
0

アクセシビリティの問題である可能性があるという Jerry Stratton のコメントに同意します。ただし、Safari が受け入れる準備ができる前に、キーストローク コマンドを発行している可能性もあります。ファイルを開いている場合は、ビジーでキーストローク コマンドを見逃す可能性があります。

また、システム イベント コードを Safari コードの外に移動し、Safari プロセスではなくシステム イベントにキーストローク コマンドを実行するように指示します。これを Safari および System Events のパーツとして試してください。

注: Chrome でファイルを開くこともできません。

tell application "Safari"
    activate
    if (count of windows) is 0 then -- Remove "if" statement if you don't want to make a new window if there is none
        make new window at front
    end if

    open (POSIX path of (path to home folder)) & "/Desktop/beMine/beMine.swf"
end tell

tell application "Safari" to activate
delay 1
tell application "System Events"
    keystroke "f" using {command down, control down}
end tell
于 2015-02-15T23:33:59.277 に答える