Jump to content

Recommended Posts

I'm using the sublime project workflow with alfred, which uses mdfind to locate .sublime-project files on my system and open them in sublime text. Very slick!

However - if the .sublime-project file is stored in a hidden directory (in this case .config/) it is not indexed by spotlight and therefore cannot be located with this workflow.

 

I'm hoping there is a way to force spotlight to index specific hidden folders, or some other workaround.

 

Any ideas?

Link to post

Is that the workflow I wrote?

I had the same problem myself with my ~/.dotfiles folder.

I tried a few things to get mdfind to return the contents of hidden directories, but it won't :(

One alternative is to swap out the mdfind command for locate '*.sublime-project', but this is a lot slower and returns results you definitely don't want, such as .sublime-project files located within installed apps' bundles.

My current workaround is to just keep the project files in another directory. It's no biggie, as I only ever open them via Alfred.

Still, I'd like this to work, too, so I'll see what I can do.

Edited by deanishe
Link to post

So, I updated my ST projects workflow.

locate turned out to be something of a dead-end (its database is so rarely updated), but I added it anyway, and also support for searching individual folders with find that mdfind otherwise wouldn't search.

In addition, you can also specify globbing patterns that will exclude matching paths from the results.

Note, the searching takes place in the background, so the workflow always remains responsive (in fact, it's faster than before), even while updating. It just might take a few seconds for new files to show up in the results.

Edited by deanishe
Link to post

If you do want to go the route of "locate" or just keep your DB up to date, then you need this command:

sudo /usr/libexec/locate.updatedb

If you want to make it easier on yourself, then add the following line to your /etc/sudoers file (replacing USERNAME with your username):

USERNAME ALL=NOPASSWD:/usr/libexec/locate.updatedb

To make it even easier, then do

ln -s /usr/libexec/locate.updatedb /usr/local/bin/updatedb

If you're using my Alfred Cron workflow, then you could just create a script run however often you want with the single line: 

updatedb

after doing the previous things.

 

But, Dean's fix is obviously the best because, well, he fixed it.

Link to post

That was my first thought (keep the locate database updated), but it ultimately isn't really viable because it takes ages to update and you can't be running it every 15 minutes in any case, and you also want newly created files to show up in Alfred in a timely fashion (say a couple of minutes at the very outside).

I think the current implementation is an acceptable hack solution:

You can add a specific folder to be searched with find, and if it turns out you're rarely adding new ST project files to it (which is pretty much always the case for me), you can delete that folder from the configuration and just rely on the results from locate instead (which will have picked it up by this time).

At any rate, I'm very glad I fixed the workflow, as I added another couple of ST project files to hidden directories yesterday. Sod grubbing around in the filesystem like an animal.


The /etc/sudoers tip is an all-round amazing thing that everyone should know. I only found out about it a couple of weeks ago, and am gutted I didn't learn it sooner. To think of the amount of time I could have saved typing in my bloody passwords. I now use it for apt-get on all my Linux machines.

It might be different on OS X, but on Linux in any case, you still have to prefix the command with sudo, you just don't get asked for your password.

Link to post

I've never actually used it on a Mac, as I rarely do things in the Terminal that require sudo (I use Homebrew to install most software).

Or does that also allow you to install stuff/change network settings without your password? That would be awesome!

Link to post

Take a look at the update for my DHCP Toggle workflow. It lets you change IP / router settings easily, but it also contains a nice little script to add yourself to the sudoers file. (When messing with your /etc/sudoers file, always check it with visudo — see the add-sudo.sh script there, or look at the one in the Sudoers workflow).

 

Basically look at this entry:

$USER ALL=NOPASSWD:/usr/sbin/networksetup

$USER is, obviously, the username (make sure you fill that in).

ALL where it can come from (so, you might consider restricting this to localhost)

 

And /usr/sbin/networksetup is the command that you get to use. You can also set it so that it has args in it so that you can use the command only with certain args. You still need to use sudo before entering the command. But doing so also lets you use sudo without needing the interaction, so, behind an Alfred script, sudo will always fail (unless you pipe the password, which I need not tell you is a terrible idea) unless you've added the line to /etc/sudoers.

 

I can't remember if you can do such a thing with the OS X GUI, but you could fake it by creating a few workflows that use sudo after you added the appropriate commands to the /etc/sudoers file.

Link to post

If you want to bake the sudo functionality into any of your workflows, look at the DHCP toggle one.

 

Unfortunately, running `cat /etc/sudoers` requires a password, so that's not the best way to check it. I just wrote in a sort of sudo-flag in the data directory once the user adds sudo functionality. If that file is there, then it uses sudo; if not, then it doesn't (and prompts the user for a password each time).

Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...