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

Unfocus search field in Safari when browsing RSS feeds Web Browsers
When you view an RSS feed in Safari, I find it annoying that Safari automatically focuses the Search box. This prevents me from scrolling by hitting space or using my mouse's scroll weel until I click somewhere else first. Of course, if I accidentally click on an article, then I'm taken there, which is even more annoying.

So, to prevent the focusing, you need to edit this file: /System -> Library -> PrivateFrameworks -> SyndicationUI.framework -> Versions -> A -> Resources -> Articles.js.

Open the file in your favorite text editor, and look for the following JavaScript function:
function setupFilter( )
{
    var filterField = document.getElementById("searchfield");
    filterField.focus();
    setFilterString(filterField.value);
    sPrefiltered = (sFilterString != null);
}
Comment out the filterFeild.focus line by putting two forward-slashes at the front of it, like so:
function setupFilter( )
{
    var filterField = document.getElementById("searchfield");
//    filterField.focus();
    setFilterString(filterField.value);
    sPrefiltered = (sFilterString != null);
}
And save the file and restart Safari. No more auto-focus! To restore the auto-focus, just remove the two slashes you added and restart Safari again.
    •    
  • Currently 2.50 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (2 votes cast)
 
[7,464 views]  

Unfocus search field in Safari when browsing RSS feeds | 9 comments | Create New Account
Click here to return to the 'Unfocus search field in Safari when browsing RSS feeds' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
there was an old hint…
Authored by: nick on Sep 29, '06 08:17:24AM

…describing how to make the searchfield loose focus as soon as you press the space bar. i can't find it, though.



[ Reply to This | # ]
Just press TAB!
Authored by: aureliojargas on Nov 22, '07 03:21:39AM

No need to edit this file. Just press TAB and the focus will jump to the content. Then you can use space, arrows, page down, etc to scroll. Tested on Safari 3.



[ Reply to This | # ]
Just press TAB!
Authored by: vykor on Jan 26, '08 02:16:16PM

Hm, doesn't seem to work for me. Hitting tab kicks focus over to my URL address bar, then the Google search box, and finally back to the search box again.



[ Reply to This | # ]
Unfocus search field in Safari when browsing RSS feeds
Authored by: Roquentin on Sep 29, '06 08:45:10AM

While it's true that the Search field won't receive the focus, neither it seems does the feed area. I've still got to click once somewhere in the feed area (carefully avoiding an article link) before the spacebar scrolling works.



[ Reply to This | # ]
no focus
Authored by: hayne on Sep 29, '06 01:20:32PM

I think the situation where there is no focus is when the page is still loading.
E.g. with my SlashDot feed, where there are almost 300 articles, it takes many seconds to finish loading.
The Javascript 'onload' function mentioned in this hint only runs after the page has finished loading.



[ Reply to This | # ]
Unfocus search field in Safari when browsing RSS feeds
Authored by: ra5ul on Sep 29, '06 07:09:54PM
i can confirm sartre's comment about there being no focus, even after the page has fully loaded. the same thing happens when using filterField.blur(); focus is mysteriously lost instead of transferring to the main content (which happens with most input fields).

[ Reply to This | # ]
Unfocus search field in Safari when browsing RSS feeds
Authored by: Roquentin on Sep 29, '06 08:55:16AM
Here's the previous hint on this subject: 10.4: Allow space bar scroll from Safari RSS search field.

[ Reply to This | # ]
safer editing via a Perl script
Authored by: hayne on Sep 29, '06 02:14:17PM
Here is a Perl script that does the editing described by this hint. It makes a backup copy of the file with a ".orig" suffix. (See this Unix FAQ if you need help on running scripts.)

#!/usr/bin/perl
use strict;
use warnings;

# removeFocusOnRss
# This script edits the Javascript file used by Safari's RSS page
# so that it doesn't place the keyboard focus in the RSS search field.
# See: http://www.macosxhints.com/article.php?story=20060924130906315
#
# Cameron Hayne (macdev@hayne.net)  Sept 2006

my $frameworkDir = "/System/Library/PrivateFrameworks/SyndicationUI.framework";
my $resourcesDir = "$frameworkDir/Resources";
my $jsfile = "$resourcesDir/Articles.js";
my $backupSuffix = ".orig";
$^I = $backupSuffix;  # edit in place, saving a copy to ".orig"
@ARGV = ($jsfile);    # make the "<>" magic apply to $jsfile

my $username = $ENV{'SUDO_USER'} ? $ENV{'SUDO_USER'} : $ENV{'LOGNAME'};
my $date = localtime();

if (! -w $resourcesDir)
{
    print STDERR "No write permission on \"$resourcesDir\"\n";
    print STDERR "Aborting\n";
    exit;
}

print STDERR "Editing \"$jsfile\"\n";

# We abort if there is already a ".orig" file
if (-e "$jsfile$backupSuffix")
{
    print STDERR "There is already a \"$backupSuffix\" copy of \"$jsfile\"\n";
    print STDERR "Aborting\n";
    exit;
}

my $targetFunc = "setupFilter";
my @linesToAdd = (
                 "// Following line commented out by $username ($date)",
                 );

while (<>)
{
    if (/^function $targetFunc\(/ .. /^}/)
    {
        if (/^\s*filterField\.focus\(\);\s*$/)
        {
            print join("\n", @linesToAdd), "\n";
            s|^|//|; # add "//" at the beginning of this line
            print STDERR "Commented out the focus line in \"$jsfile\"\n";
            print STDERR "Original file saved as \"$jsfile$backupSuffix\"\n";
        }
    }
    print;
}

# print a 'diff' of the files just as a confirmation that all went as planned
print STDERR "Changes made to \"$jsfile\":\n";
print STDERR `diff $jsfile$backupSuffix $jsfile`;
By the way, I decided not to make this change to the Articles.js file since my major problem is with the case when the page hasn't finished loading yet. As mentioned in an earlier comment, in this case the Javascript onload function hasn't been called yet, so this hint doesn't help things. And I usually page down with the arrow keys in any case and these are specially provided for in the code for the search field.

[ Reply to This | # ]
Unfocus search field in Safari when browsing RSS feeds
Authored by: nicksageek on Oct 01, '06 09:18:06AM

Nicely done, works like a charm.



[ Reply to This | # ]