Jump to content

I want to create a workflow to pull up my current background photo in Finder.

Recommended Posts

I have a folder with 500+ images that I use as my desktop backgrounds, and I have them set to cycle randomly every 5 minutes. Sometimes when a photo pops up I want more information about it, but since the photos are all named fairly randomly, it's hard to find the photo I want among so many.


Would there be a way for Alfred to figure out which photo was currently up in the background and then take me to the original file in Finder?


I would love it if someone could tell me how to create a workflow like this, or even do it themselves, because I have absolutely no experience with this kind of stuff. Thanks!


EDIT: Bonus points if there was also a way to have Alfred automatically search Google Images with the photo after it locates it in Finder!

Edited by sr_navarre
Link to comment

What information do you want from the image? I mean, David's applescript to reveal the file just requires one more keypress ( CMD+i ) to get the info for the file from finder.


And with the google image search ... do you mean you want Alfred to upload the image to google images to find similar? Or, just the name of the image?

Link to comment

What information do you want from the image? I mean, David's applescript to reveal the file just requires one more keypress ( CMD+i ) to get the info for the file from finder.


And with the google image search ... do you mean you want Alfred to upload the image to google images to find similar? Or, just the name of the image?


Hi Rodger,


David's script only brings me to the folder that the image is in. There are still 500+ images to go through to find it, which is what I'm trying to avoid. The main points of info that I would like about the image are actually things that would only be available through Google Images, which I could search manually if I could figure out how to make the first part of the workflow. I just thought I'd throw it in there in case anyone wanted to take a stab at it.

Link to comment

Are you saying that when the Finder window opens that the image is NOT selected?  Because, that is what is SUPPOSED to happen with the 'reveal'.

Right, that's what I'm saying. When Finder opens, the first image in the folder (by name) is selected, no matter what is showing as the wallpaper. I was looking to make a workflow that would take me to the exact file that was currently being used as a wallpaper. I'm not very good with this stuff, so I apologize if I explained it wrong.

Link to comment

That is very strange to me. Can you try something for me?


Edit the script ... clear what's there and replace with:

tell application "System Events"
set posix_path to (picture of current desktop)
set file_ref to (POSIX file posix_path) as alias
set file_name to displayed name of file_ref
end tell
tell application "Finder"
reveal file_ref
end tell

This uses System Events first, to grab the info, and posix path ... then Finder to REVEAL the file in a new window.  It SHOULD select the file.  The original method works fine (just not for you) ... but this does essentially the same thing for me.

Link to comment

Thanks for trying to help, but even after replacing the original script with what you wrote, it still just selects the first picture in the folder, not the one that's being used for the wallpaper. Oddly enough, it also opens finder behind all of my other windows, which is not a problem, but not what I would have expected. 

Link to comment

ok, another test:


Open Apple "Script Editor"


in the top window, the big blank space, put the following:

tell application "Finder"
set temp to (get the desktop picture as alias)
end tell

Then, hit the PLAY button at the top and look at the result pane at the bottom.

Does the result show the correct path to the current wallpaper?


For example, when I do this, my result is:

alias "Macintosh HD:Users:Rodger:Pictures:Wallpapers:Apple 5K iMac Waterfall.jpg"
Link to comment

What I am thinking now is that the database the desktop picture is stored in 'may' be corrupted.  In Yosemite, this is located:


/Users/username/Library/Application Support/Dock/desktoppicture.db


If you remove that file, then reboot your machine, that will restore the default desktop picture installed with Yosemite, and subsequently rewrite the database.  Then, if you change your desktop picture to whatever you want, and run the previous script from the Script Editor, does it show the correct image?

Link to comment

This is perplexing. Do you have more than one display? Or, do you have multiple spaces with a different image on each? Is your custom folder on an external drive? How, exactly, do you set the image for your wallpaper?


Basically, the original script should just work ... the fact that it is not leads me to think something is 'in the way'.

Link to comment

I do not have any of those things -- my folder is on my internal SSD. I don't have any other display than the laptop screen. I do sort of use spaces, but only because I keep a couple of my apps in full-screen.


To set the image for my wallpaper, I created a folder which I call "Backgrounds." It's got about 500 pictures in it. Then, in System Preferences -- Desktop & Screensaver -- Desktop, I set it to pull images from that folder and change them in random order every 5 minutes.

Link to comment

OK, another test:


Open Alfred and type "Calculator" ... as if you wanted to launch it.

Then, highlight Calculator and hit the right arrow to bring up Alfred's file actions.

In that list, select "Reveal in Finder"


Does it open a Finder window and SELECT the Calculator app?

Link to comment

OK, I have managed to replicate your issue!  It seems that the normal method of finding the desktop pic works mainly for NON-rotated images. SO, we need to find a way that will work with the image cycler.


Phew ... this was driving me nuts, but at least we are making headway.

Link to comment

With a bit more research I have found out the following:


For Mavericks + we need to read from the "/Users/username/Library/Application Support/Dock/desktoppicture.db", which is a sqlite3 database.


The thing is, this db stores multiple images, based on whether or not rotation is on or off.


The final script will have to have a function (I think) to check the rotation setting.  If rotation is on, then grab the rotation image, and if it is off then grab the static image instead.


As we found out earlier, the Finder/System Events scripts only find the static image.  This simply doesn't work with image rotation ... hence reading the 'desktoppicture.db' with sqlite3 becomes necessary.


Parsing the data is a bit beyond me ... we need someone with more experience I think in that department.


For instance:


Open up the Apple Script editor again, and paste the following into it ... then hit play.

set a to (do shell script "sqlite3 ~/Library/Application\\ Support/Dock/desktoppicture.db \"SELECT data.value FROM preferences INNER JOIN data on preferences.key=16 and preferences.picture_id=3 and preferences.data_id=data.ROWID\"") as POSIX file
set b to a as string
set {ASTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ":"}
set y to end of text items of b
set AppleScript's text item delimiters to "."
set c to text item 1 of y
set AppleScript's text item delimiters to ASTID
return c

That script SHOULD Result with the name of the current desktop image ... with rotation on.

Link to comment

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...