Skip to content

Instantly share code, notes, and snippets.

@blia
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blia/2b971ebc56b1ab0bd29d to your computer and use it in GitHub Desktop.
Save blia/2b971ebc56b1ab0bd29d to your computer and use it in GitHub Desktop.
Play/Pause Yandex.Music AppleScript for Automator
-- Open automator
-- Create new service
-- Set Service recives selected to no input in any application
-- Move Run AppleScript to workflow
-- Past this script
-- Save with name like "Play Yandex Music". Do not use slashes, dots etc.
-- Goto System Preferences / Keyboard / Shortcuts / App Shortcuts / All applications
-- Press +
-- Set Menu title as your service name from step 6 (you can check name by selecting services menu from App menu)
-- Set key
-- Enjoy!
tell application "Safari"
set searchpat to "music.ya"
set winlist to every window
set winmatchlist to {}
set tabmatchlist to {}
set tabnamematchlist to {}
repeat with win in winlist
set ok to true
try
set tablist to every tab of win
on error errmsg
--display dialog name of win as string
set ok to false
end try
if ok then
repeat with t in tablist
if searchpat is in (name of t as string) then
set end of winmatchlist to win
set end of tabmatchlist to t
set end of tabnamematchlist to (id of win as string) & "." & (index of t as string) & ". " & (name of t as string)
--display dialog name of t as string
else if searchpat is in (URL of t as string) then
set end of winmatchlist to win
set end of tabmatchlist to t
set end of tabnamematchlist to (id of win as string) & "." & (index of t as string) & ". " & (name of t as string)
--display dialog name of t as string
end if
end repeat
end if
end repeat
if (count of tabmatchlist) = 1 then
--display dialog "one!"
set w to item 1 of winmatchlist
set t to item 1 of tabmatchlist
set current tab of w to t
set index of w to 1
activate
tell application "System Events"
key code 49
end tell
else if (count of tabmatchlist) = 0 then
else
set whichtab to choose from list of tabnamematchlist with prompt "The following tabs match, please select one:"
set AppleScript's text item delimiters to "."
if whichtab is not equal to false then
set tmp to text items of (whichtab as string)
set w to (item 1 of tmp) as integer
set t to (item 2 of tmp) as integer
set current tab of window id w to tab t of window id w
set index of window id w to 1
activate
tell application "System Events"
key code 49
end tell
end if
end if
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment