2016-09-10 17 views
2

私はApple Remoteで(BetterTouchToolを介して)Soundcloudでの再生/一時停止を行うAppleScriptで作業しています。Apple RemoteでSoundcloudタブを再生/一時停止する

iTunesのネイティブApple Remote ▶/❚❚ボタンと同じように動作するはずです。 SoundCloudでは、keystroke space)はです。再生/一時停止再生;

  • なしてSoundcloudタブが存在しない場合は、てSoundcloudタブとkeystroke space)を開きます。
  • 1てSoundcloudタブが存在する場合は、それを選択し、keystroke space(う既に再生、または他の場合‖)。
  • 複数てSoundcloudのタブが存在する場合、最初のものを選択し、keystroke space(どちらか‖はタブが再生されている場合は、タブを別のタブが再生されている場合こと、または何のタブが再生されていない場合) 。

これまでのところ、新しいタブを開いて再生を開始することができました。既に存在する場合は、そのタブを選択しますが、再生/一時停止しません。また、Soundcloudタブがすでにアクティブです。

私はAppleScriptの初心者ですので、残念ながら私ができることは実験することです。助けに感謝します。

+1

「戻る」はスクリプトを終了します。それを 'exit repeat'に変更すると、タブを見つけてもスクリプトは停止しません。 'open location'はリピートループにあるはずです。それ以外の場合は毎回開きます。 – user309603

+0

@ user309603:ありがとう、私はこれを試しましたが、あなたが指していた結果が得られませんでした。たぶん私はそれを間違っていた?あなたが傾いている場合は、質問に答えてください。 – Winterflags

答えて

1

スクリプトがループを終了する必要があり、スクリプトは次のように、if条件が必要になります。

set soundcloudTab to false 
tell application "Google Chrome" 
    repeat with w in windows 
     set i to 1 
     repeat with t in tabs of w 
      if URL of t starts with "https://soundcloud.com" then 
       set active tab index of w to i 
       set index of w to 1 
       set soundcloudTab to true 
       exit repeat 
      end if 
      set i to i + 1 
     end repeat 
     if soundcloudTab then exit repeat -- exit windows loop 
    end repeat 
    activate 
    if not soundcloudTab then -- no Soundcloud tab exist 
     open location "https://soundcloud.com/you/likes" 
     delay 3 
    end if 
end tell 
tell application "System Events" to keystroke space 
別の解決策は、 playPauseボタンをクリックし JavaScriptを使用することです

(なしタブを有効にする必要があります。「Google Chrome」は、フォアグラウンドにする必要はありません。

set soundcloudTab to missing value 
tell application "Google Chrome" 
    repeat with w in windows 
     tell (first tab of w whose URL starts with "https://soundcloud.com") to if exists then 
      set soundcloudTab to it 
      exit repeat 
     end if 
    end repeat 
    if soundcloudTab is missing value then 
     open location "https://soundcloud.com/you/likes" 
     delay 3 
     set soundcloudTab to active tab of front window 
    end if 
    tell soundcloudTab to execute javascript "document.getElementsByClassName('playControls__playPauseSkip')[0].getElementsByTagName('button')[1].click()" 
end tell 
+0

非常にきちんとしたJavaScriptソリューションで、現在Apple RemoteがSoundcloudを再生できます:)ありがとうございます! – Winterflags

0

このポストの上につまずく誰もここにどのようにだ、彼らのApple RemoteでてSoundcloudを制御したい場合:

はすでにBetterTouchToolを持っていると仮定すると、あなたは再生/一時停止のためのApple Remoteタブにトリガを追加することができますトラック:プレイ用

enter image description here

、アッシgn Appleスクリプトとして定義済みアクションとして実行します。 @ jackjr300JavaScriptソリューションをコピーして貼り付け、[保存]をクリックします。

次の場合

と前、同じJavaScriptを貼り付けるちょうどに.getElementsByTagName('button')[1]を変更:ため

  • .getElementsByTagName('button')[2]ため

    • .getElementsByTagName('button')[0]
  • 1

    上記を踏まえて、私は短くて脆弱な解決策を思いつきました。私の使用例では、SoundCloudのタブが1つだけ開いていることを前提としています。メインルーチンは次のとおりです。

    on controlSoundcloud(cmd) 
        tell application "Google Chrome" 
         repeat with theTab in every tab in every window 
          if URL of theTab starts with "https://soundcloud.com" then 
           execute theTab javascript "var el = document.querySelector('button.playControls__" & cmd & "'); el && el.click()" 
           return 
          end if 
         end repeat 
        end tell 
    end controlSoundcloud 
    

    それだけでは何もしません。あなたはまだそれを呼び出す必要があります。あなたが何をしたいかに応じて、スクリプトの最後までこれらの行の1つをタックします。

    -- play/pause 
    controlSoundcloud("play") 
    -- prev 
    controlSoundcloud("prev") 
    -- next 
    controlSoundcloud("next") 
    
    関連する問題