Jump to content

alfo3311

Member
  • Posts

    3
  • Joined

  • Last visited

Recent Profile Visitors

222 profile views

alfo3311's Achievements

Helping Hand

Helping Hand (3/5)

0

Reputation

  1. I found the solution. I needed to write 'my' in front of replace_chars when I call the handler.
  2. Hi, Can I use subroutines in NSAppleScript Alfred workflows? I can't get this code to work: on alfred_script(q) tell application "Google Chrome" repeat with t in tabs of windows tell t if URL starts with "http://www.youtube.com/watch" or URL starts with "https://www.youtube.com/watch" then set new_URL to URL set new_URL to replace_chars(URL, "youtube", "yourepeat") do shell script "/usr/bin/open -a '/Applications/Google Chrome.app' " & new_URL end if end tell end repeat end tell end alfred_script to replace_chars(this_text, search_string, replacement_string) set AppleScript's text item delimiters to the search_string set the item_list to every text item of this_text set AppleScript's text item delimiters to the replacement_string set this_text to the item_list as string set AppleScript's text item delimiters to "" return this_text end replace_chars Trying to debug the issue, I pasted the code in Automator (and made a few changes of course), and here's the syntax error I get: Google Chrome got an error: item 1 of every tab of every window doesn’t understand the “replace_chars” message. I tried putting the 'to replace_chars' subroutine in other places in the code, but it doesn't work. Any help would be grealtly appreciated it.
  3. Hi I greatly appreciated your workflow in the past. I tried to fix it but the problem doesn't seem to come from the YouTube API, but maybe I'm wrong. Here's my results so far. If I visit a YouTube page, pause the video, and type the following code in the console, it works (the video plays): var player = document.getElementById('movie_player'); player.startVideo(); When I type 'ytp' in the alfred bar though, the video doesn't play, and the console outputs 'Uncaught error: getPlayerState() not a function.' I checked on the API, the functions getPlayerState() and pauseVideo() are still there and are the same. The problem I found is that somehow the line 'var player = document.getElementById('movie_player');' in the Alfred workflow doesn't change the player variable. I tested this by typing 'player' in the Chrome console. It outputs a different default player object, for which of course there's no getPlayerState, etc. functions. My conclusion was that... I was confused. I thought maybe the default player object already present is 'protected' and can't be overridden when Alfred executes the javascript code? If you can get this action (ytp) to work, I am willing to update the rest of the workflow. Thank you very much.
×
×
  • Create New...