Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Automate the download of YouTube videos in Safari 5.1 Web Browsers

A YouTube video can be downloaded by Option-double-clicking its video URL in Safari's Activity window. (See this hint.) However, if a lot of tabs are open, the URL can be difficult to find; particularly as now it will often have no "MB" value in the Status column.

This script will find the YouTube video URL of the current tab in the Activity window, and attempt to download it in Safari. You will need to always have at least one download in the Downloads popover to make it available! Otherwise, the script leaves the video URL highlighted for an Option-double-click download. Run the script with your favourite app launcher.

It works by first searching the Activity window for the name of the current Safari tab, then opening the disclosure triangle to find the "videoplayback" URL. Then, if its available, the "Show Downloads" button is clicked and its popover is brought into focus. Finally, the script pastes in the video URL for downloading.

There are some delays in the script that can be un-commented if you find it goes too fast for the windows on your Mac to keep up with. (The delays are not necessary on my mid-2011 MacBook Air.) Change the _videoName value if there's another kind of unique element you'd like to download instead.

A couple of incidental things I noticed about the Downloads popover: it can only be brought into focus by clicking its list first (clicking its buttons won't work otherwise), and clicking "Clear" when a file is downloading will clean up its list without removing the downloads button from Safari's toolbar.

Here's the AppleScript code:
try
	set _videoName to "videoplayback"
	set _downloadButtonAvailable to true
	
	tell application "Safari" to activate
	-- delay 0.5
	tell application "Safari" to set _windowName to name of current tab of window 1
	
	
	tell application "System Events"
		tell process "Safari"
			try
				set _downloadButton to item 1 of (every button whose description = "Downloads") of tool bar 1 of window _windowName
			on error a number b
				set _downloadButtonAvailable to false
			end try
			
			tell menu item "Activity" of menu "Window" of menu bar item "Window" of menu bar 1 to click
			try
				window "Activity"
			on error a number b
				tell menu item "Activity" of menu "Window" of menu bar item "Window" of menu bar 1 to click
			end try
			
			-- delay 0.5
			
			tell outline 1 of scroll area 1 of window "Activity"
				
				set _count to count of rows
				try
					repeat with i from 1 to _count
						tell group 1 of row i
							try
								try
									set _triangleValue to value of UI element 1
									if _triangleValue = 1 then
										tell UI element 1 to click
										-- delay 0.2
									end if
									tell text field 1 to set _value to value
									if _value = _windowName then exit repeat
								end try
								value of text field 1
							on error a number b
								exit repeat
							end try
						end tell
					end repeat
				end try
				
				set _count to count of rows
				
				repeat with n from 1 to _count
					try
						tell group 1 of row n
							tell text field 1 to set _value to value
							
							if _value = _windowName then
								set _row to n
								set _triangleValue to value of UI element 1
								if _triangleValue = 0 then tell UI element 1 to click
								exit repeat
							end if
						end tell
					end try
				end repeat
				
				set _count to count of rows
				
				repeat with x from _row to _count
					try
						tell row x
							tell text field 1 to set _value to value
							if _value contains _videoName then
								set _url to value of text field 1
								if _downloadButtonAvailable = false then select
								exit repeat
							end if
						end tell
					end try
				end repeat
				
			end tell
			
			try
				_url
			on error a number b
				error "The '" & _videoName & "' URL couldn't be found."
			end try
			
			if _downloadButtonAvailable = true then tell menu item "Activity" of menu "Window" of menu bar item "Window" of menu bar 1 to click
		end tell
	end tell
	
	
	if _downloadButtonAvailable = false then
		tell application "Safari"
			activate
			display dialog "The 'Show Downloads' button is not available. 
			
Option-click the selected '" & _videoName & "' URL to download the video." with title "Safari YouTube Video Downloader"
		end tell
		
	else
		set the clipboard to _url
		-- delay 0.5
		
		tell application "System Events"
			tell process "Safari"
				try
					pop over 1 of _downloadButton
				on error a number b
					click _downloadButton
				end try
				set focused of list 1 of scroll area 1 of pop over 1 of _downloadButton to true
			end tell
			-- delay 0.5
			keystroke "v" using command down
		end tell
	end if
	
on error a number b
	if a does not contain "user canceled." then tell application "Safari" to display dialog a with title "Safari YouTube Video Downloader"
end try
[kirkmc adds: I tried this with a few videos, and it works. That's some pretty impressive AppleScripting. One question: can't you make the Downloads popover visible by sending a Command-Option-L keystroke?]
  Post a comment  •  Comments (11)  
  • Currently 3.60 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (5 votes cast)
 
[12,014 views] Email Article To a Friend View Printable Version
10.7: Keep Silver Aerogel blur effect in Terminal at all times System 10.7
When using the 'Silver Aerogel' theme with Terminal, it blurs text underneath the window, but only if Terminal is the active application. I find the inconsistency a little jarring. Fortunately, this can be changed.

In Terminal, perform the following commands:
echo -e "defaults write com.apple.Terminal '" >| output.$$
defaults read com.apple.Terminal | sed -e 's/(BackgroundBlurInactive.*)0/11/' >> output.$$
echo ' >> output.$$
eval $(cat output.$$)
rm output.$$
NOTE: you may need to change this a little if you're not using bash. Presumably you know what to put if you've changed your shell. If you don't what that means, then you're using bash.

Quit Terminal. Now, when you relaunch it, your Aerogel windows will maintain the blur effect even if they're not the active window.

[kirkmc adds: I didn't go to the trouble of testing this, because blurred text gives me a headache. But that theme does, indeed, blur text by default. If anyone wants to confirm that this works...]
  Post a comment  •  Comments (8)  
  • Currently 2.44 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (9 votes cast)
 
[3,750 views] Email Article To a Friend View Printable Version
Setting unlisted keyboard shortcuts for Mission Control and Dashboard Apps
While the Mission Control preference pane allows you to map common keyboard shortcuts to Mission Control actions, its interface doesn't allow you to map more esoteric keys like F19. Here's a quick way to assign an unlisted keyboard shortcut to one of the Mission Control actions.

Go to the Keyboard preference pane, then the Keyboard Shortcuts tab, select Mission Control and enter your keyboard shortcut there. It will automatically be reflected in the Mission Control preference pane. No need to muck around with Terminal commands!

[kirkmc adds: This is a good reminder that other features that offer a limited set of keyboard shortcuts may be available to change in the Keyboard Shortcuts pane of the Keyboard preferences. For example, the Spotlight preference pane offers a number of shortcuts, but you may want something other than what's in its menu. You can set any shortcut you want in the Keyboard preference pane.]
  Post a comment  •  Comments (2)  
  • Currently 3.29 / 5
  You rated: 4 / 5 (7 votes cast)
 
[3,943 views] Email Article To a Friend View Printable Version
Workaround for Logic Pro bug which stops recordings Apps
I discovered a bug in Logic Pro by missing the last movement of a symphony recording: if you unplug your headphones, Logic stops recording. I'm assuming this is because it switches from line out to speakers.

The solution is to route the output of Logic to Soundflower. Launch another audio application (e.g., Amadeus Pro), set its input to Soundflower, the output to headphones or speakers, then launch any operation that allows monitoring the signal. (In Amadeus, open a real-time sonogram window and select Play Through.) Unplugging the headphones now no longer interrupts recording in Logic Pro.

[kirkmc adds: I haven't tested this; I don't use Logic Pro.]
  Post a comment  •  Comments (5)  
  • Currently 4.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[2,661 views] Email Article To a Friend View Printable Version
Remove completed items from Reminders list iOS devices
When I tap the checkboxes next to items in your Reminders list to mark them complete, I usually want them to go away, so I don't have to scroll up and down, especially when I have a long list of things to do or buy.

To quickly force the marked items to move into the Completed section I noticed that if I slightly swipe to left or right so that part of the next or previous Reminders list appears, then release so that I stay in my current list, the completed items get moved over, and only the uncompleted ones remain.
  Post a comment  •  Comments (1)  
  • Currently 3.43 / 5
  You rated: 5 / 5 (7 votes cast)
 
[3,925 views] Email Article To a Friend View Printable Version
Quickly expand and shrink Save dialogs System 10.7
In recent versions of Mac OS X, the standard Save dialog box was replaced with a more compact sheet giving only a text field for providing a file name, a popup menu to choose a save location, and sometimes are some specific options such as text-encoding or file-type, along with the Save and Cancel buttons.

There's a disclosure triangle to expand the Save panel into the full size one, giving access to the whole file system.

But you can toggle between the compact and full-size versions by pressing Command-= (equals).

[kirkmc adds: Nice catch. I was sure this would have been on the site, but can't find anything. It's worth noting that applications remember the state of the dialog box, so if you expand it once, they will always display the large dialog.]
  Post a comment  •  Comments (7)  
  • Currently 4.55 / 5
  You rated: 3 / 5 (11 votes cast)
 
[4,604 views] Email Article To a Friend View Printable Version
Zoom when Login window is visible System
If you have poor vision, and multiple accounts display in a Login window, you can turn on zoom, and zoom in and out as needed to see the different user names and icons. (This assumes that zoom is not already turned on.) This uses the standard keyboard shortcuts that display in the Universal Access preference pane.

To turn on zoom, press Command-Option-8.

To zoom in, press Command-Option- = (equals).

To zoom out, press Command-Option- - (minus).

You may need to move the window around to see the different login icons. You can do this by moving the cursor to the edge of the screen.

[kirkmc adds: there have been plenty of hint about using the zoom feature, but it's worth noting that it can be activated and used even when the Login window is visible.]
  Post a comment  •  Comments (0)  
  • Currently 3.29 / 5
  You rated: 5 / 5 (7 votes cast)
 
[3,658 views] Email Article To a Friend View Printable Version
Recover disk space used by hidden Dropbox files Apps
I use Dropbox to sync files across my Macs, but also to collaborate with others on several projects. One day, I woke up to find the disk space on my MacBook Air had dropped substantially. I started poking around, looking for large files, swap files and the other usual suspects. I eventually found a hidden folder inside my Dropbox folder: .dropbox.cache.

Looking inside this folder, I found that it contained three dated folders, for the past three days. (For example, 2012-03-01.) Inside this folder were a number of files, and since on one shared project we use a standard versioning system, I was able to see that there were subsequent versions of these files, with names indicating that they had been deleted.

All in all, I recovered 8 GB that day, because there were two projects where people had change a lot of files. On a desktop Mac, this won't usually make much of a difference, but if you have a MacBook Air, in particular, without much disk space, you may suddenly find yourself out of room. So, if you see a sudden decrease in disk space, you can check this folder. If you use Terminal you know how to get there; if not, you can open it from the Finder. Choose Go > Go to Folder, and enter ~/Dropbox/.dropbox.cache (assuming that your Dropbox folder is at the default location at the top level of your home folder; change the path if it is not). You can delete the folders with no worry of losing files.
  Post a comment  •  Comments (6)  
  • Currently 4.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (7 votes cast)
 
[13,928 views] Email Article To a Friend View Printable Version
Message from the management: new editor for Mac OS X Hints Site News
Greetings, Hintlings,

As of today, I am taking over as editor of Mac OS X Hints. Old-timers may recognize my name: I guest edited a number of times when Rob was on vacation or having kids. For those who don't know me, I'm a senior contributor to Macworld, where I am also the iTunes Guy, and I've written a couple of Take Control books, most recently about Scrivener and iTunes. If you want to learn more about me, check out my web site, Kirkville.

I'd like to thank Craig for all the work he's done here over the years. I wish him the best as he moves on to other ventures, and I hope you'll all join me in giving him a big thank you!
  Post a comment  •  Comments (10)  
  • Currently 5.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (6 votes cast)
 
[3,310 views] Email Article To a Friend View Printable Version
Farewell! Site News
Starting today, MacOSXHints has a new editor. Kirk McElhearn, who I'm sure many of you already know, will be at the helm. Treat him well.

My thanks to all of you as readers, and especially those of you who are hint submitters. It's been a remarkable time in Apple's evolution, and I hope there will be plenty of good tips both for Lion and Mountain Lion in the future. I very much look forward to reading them, and maybe adding a few myself.

Thanks again, and see you soon.

Craig A.
  Post a comment  •  Comments (11)  
  • Currently 5.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (8 votes cast)
 
[3,115 views] Email Article To a Friend View Printable Version