Apple Favorites wallpaper handling

  1. Is it possible at all to generate ascript which can pull up EXIF data on the current wallpaper?

My wallpapers are my favorites in Apple Photos, and it’d be great if I could hit a defined function key and find out the location and date the photo was taken.

90% of the time I know the location but…

  1. Secondly is it possible to generate a script which will rotate the wallpaper to the next image in the sequence?

Thanks as always for your thoughts.

If it helps this page shows how to get the location of the file being used and write it on top of the desktop picture in use:

https://osxdaily.com/2011/11/20/show-the-location-path-of-current-wallpaper-in-mac-os-x/

Also found this but no ideas how to run it:

https://discussions.apple.com/thread/8373854?answerId=33344100022#33344100022

And this will reportedly extract EXIF data (but doesn’t work):

https://macosxautomation.com/applescript/imageevents/09.html

So somehow I need to fix the second script, merge it with the first… and then display the data?

In fact the first script would work if I could open the photo in the Photos app instead of in Finder? I’ve tried replacing ‘Finder’ with ‘Photo’ or ‘Photos’ to no avail.

One by one

Getting LOCATION of current desktop picture file:


-- get current Pictures folder
tell application "System Events" to set pFldr to pictures folder of current desktop

-- get relative posix path of picture (in the cash)
set POSIXPath to pFldr & "/" & paragraph 1 of (do shell script "ls -tu " & quoted form of pFldr)

-- get full Posix path of current desktop picture
tell application "Finder" to set pictureFileAsAlias to POSIXPath as POSIX file as alias
set currentPicturePOSIXPath to POSIX path of pictureFileAsAlias

Getting EXPOSURE TIME of current desktop picture file (Note: it will return empty string if the picture file doesn’t contain any exposure time info):

  1. Install ExifTool on your MAC. It is free and only realable solution on this moment. Adjust script this way:

property exiftoolPath : "/usr/local/bin/exiftool"

-- get current Pictures folder
tell application "System Events" to set pFldr to pictures folder of current desktop

-- get relative posix path of picture (in the cash)
set POSIXPath to pFldr & "/" & paragraph 1 of (do shell script "ls -tu " & quoted form of pFldr)

-- get full Posix path of current desktop picture
tell application "Finder" to set pictureFileAsAlias to POSIXPath as POSIX file as alias
set currentPicturePOSIXPath to POSIX path of pictureFileAsAlias

-- Get ExposureTime tag name and value.
set exposureTime to (do shell script exiftoolPath & " -s3 -ExposureTime " & quoted form of currentPicturePOSIXPath)

If I ty to run that script within Keyboard Maestro (run applescript) I get errors, this however does work:

-- https://discussions.apple.com/thread/8373854?answerId=33344100022#33344100022
--
-- Usage: osascript find_wall_pic n

--        n = 1 or 2 (monitor ID)



on replace_chars(this_text, search_string, replacement_string)
	
	-- ref: https://www.macosxautomation.com/applescript/sbrt/sbrt-06.html
	
	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



on run argv
	
	if (count of argv) < 1 then
		
		set screenId to 1
		
	else
		
		set screenId to item 1 of argv as integer
		
	end if
	
	if screenId ≤ 1 then
		
		set screenId to 1 -- 1st monior index
		
	else
		
		set screenId to 18 -- 2nd monitor index
		
	end if
	
	
	
	--        set a to (do shell script "/usr/bin/sqlite3 ~/Library/Application\\ Support/Dock/desktoppicture.db \"SELECT data.value FROM preferences INNER JOIN data on preferences.key=16 and preferences.data_id=data.ROWID where preferences.picture_id =" & screenId & "\"") as string
	
	--        set posixaliaspath to "/Users/kangfucius/Library/Caches/com.apple.preference.desktopscreeneffect.desk top/69677504/DSKPhotosRootSource/" & a
	
	
	
	set posixaliaspath to (do shell script "/usr/bin/sqlite3 ~/Library/Application\\ Support/Dock/desktoppicture.db \"select d1.value || '/' || d2.value from preferences pf1 join data d1 on pf1.data_id=d1.rowid join preferences pf2 on pf1.picture_id=pf2.picture_id join data d2 on pf2.data_id=d2.rowid where pf1.key=10 and pf2.key=16 and pf1.picture_id=" & screenId & "\"") as string
	
	set homepath to (do shell script "echo $HOME")
	
	-- replace "~" in the path to actual $HOME dir
	
	set posixaliaspath to replace_chars(posixaliaspath, "~", homepath)
	
	
	
	set aliaspath to (POSIX file posixaliaspath) as string
	
	set posixpath to POSIX path of aliaspath
	
	set imgfile to POSIX file posixpath
	
	-- tell application "Finder" to reveal imgfile
	
	-- tell application "Finder"
	tell application "Finder"
		
		activate
		
		reveal imgfile
		
	end tell
	
end run

The only issue or what I want is that it does show the file in Finder. Ideally I want the photo to be shown in Photos, or failing that a window to open showing the EXIF data of Location, and date taken

It is not difficult for me to delete my post if it does not interest you.

I didn’t say it was of no interest just that it didn’t work for me within Keyboards Maestro.

I have installed ExifTool on the Mac and again checked out your script (not using KM) and it does indeed work, and shows the exposure time :slight_smile:

Looking at the documentation for ExifTool I can’t work out how to get it to show location data?

If the script can give out both created date (I got that working) as well as location then I’m very happy!

Hoping you can help…

I have not any photo with GPS info in it. So, add following at end of my script above and test yourself:


-- Get GPS data (location)
set GPSLatitude to (do shell script exiftoolPath & " -s3 -GPSLatitude " & quoted form of currentPicturePOSIXPath)
set GPSLongitude to (do shell script exiftoolPath & " -s3 -GPSLongitude " & quoted form of currentPicturePOSIXPath)

Exists third kind of GPS date, named DateTimeOriginal. You can try to get it this way:


set DateTimeOriginal to (do shell script exiftoolPath & " -s3 -DateTimeOriginal " & quoted form of currentPicturePOSIXPath)

So, all script should be like this (I can’t test fully):


property exiftoolPath : "/usr/local/bin/exiftool"

-- get current Pictures folder
tell application "System Events" to set pFldr to pictures folder of current desktop

-- get relative posix path of picture (in the cash)
set POSIXPath to pFldr & "/" & paragraph 1 of (do shell script "ls -tu " & quoted form of pFldr)

-- get full Posix path of current desktop picture
tell application "Finder" to set pictureFileAsAlias to POSIXPath as POSIX file as alias
set currentPicturePOSIXPath to POSIX path of pictureFileAsAlias

-- Get GPS data (location and date)
set DateTimeOriginal to (do shell script exiftoolPath & " -s3 -DateTimeOriginal " & quoted form of currentPicturePOSIXPath)
set GPSLatitude to (do shell script exiftoolPath & " -s3 -GPSLatitude " & quoted form of currentPicturePOSIXPath)
set GPSLongitude to (do shell script exiftoolPath & " -s3 -GPSLongitude " & quoted form of currentPicturePOSIXPath)

Okay that makes good progress. :slight_smile:

The output seems to be the last ‘set’ line e.g.:

“1 deg 44’ 4.87" W”

Which is from the

set GPSLongitude to (do shell script exiftoolPath & " -s3 -GPSLongitude " & quoted form of currentPicturePOSIXPath)

line. Is there no way of displaying all the output data? Or am I missing something?

The GPSLatitude & Longitude look good, but do not give the location shown in Apple Photos, I guess there is no way to get that?

You can return multiple results as list:


return {DateTimeOriginal, GPSLatitude, GPSLongitude}

Having GPSLatitude and GPSLongitude you can show location on the map with AsObjC and webview. Somewhere on this site exists example.

Following is one example from Takaaki Naganoya (firstly, you have to convert latitude and longitude from degrees to radians):

-- Created 2019-02-14 by Takaaki Naganoya
-- 2019 Piyomaru Software
use AppleScript version "2.5"
use scripting additions
use framework "Foundation"
use framework "MapKit"
use framework "AppKit"

property |NSURL| : a reference to current application's |NSURL|
property NSData : a reference to current application's NSData
property MKMapView : a reference to current application's MKMapView
property NSURLRequest : a reference to current application's NSURLRequest
property NSURLConnection : a reference to current application's NSURLConnection

property theResult : 0
property returnCode : 0

set nRes to hasInternetConnection("http://www.google.com") of me
if nRes = false then error "No Internet Connection...."

-- Карта отображает начальные координаты. Oбычно, текущая позиция выбирается и указывается с помощью Assistive-GPS через WiFi.
set aLong to 130.55723797
set aLat to 31.57868838

set paramObj to {myMessage:"Выберите местоположение", mySubMessage:"Пожалуйста, поместите целевое местоположение в центр карты", aLongitude:aLong, aLatitude:aLat}
my performSelectorOnMainThread:"chooseCoordinate:" withObject:(paramObj) waitUntilDone:true
return theResult
--> {latitude:31.57868838, longitude:130.55723797}

on chooseCoordinate:paramObj
	set aMainMes to myMessage of paramObj
	set aSubMes to mySubMessage of paramObj
	set aLong to aLongitude of paramObj
	set aLat to aLatitude of paramObj
	
	-- Создать MKMapView
	set aMapView to MKMapView's alloc()'s initWithFrame:(current application's NSMakeRect(0, 0, 500, 300))
	tell aMapView
		its setMapType:(current application's MKMapTypeStandard)
		its setZoomEnabled:true
		its setScrollEnabled:true
		its setPitchEnabled:true
		its setRotateEnabled:true
		its setShowsCompass:true
		its setShowsZoomControls:true
		its setShowsScale:true
		its setShowsUserLocation:true
		
		set aLocation to current application's CLLocationCoordinate2DMake(aLat, aLong)
		its setCenterCoordinate:aLocation zoomLevel:17 animated:false
		its setDelegate:me
	end tell
	
	-- set up alert	
	set theAlert to current application's NSAlert's alloc()'s init()
	tell theAlert
		its setMessageText:aMainMes
		its setInformativeText:aSubMes
		its addButtonWithTitle:"OK"
		its addButtonWithTitle:"Cancel"
		its setAccessoryView:aMapView
	end tell
	
	-- show alert in modal loop
	current application's NSRunningApplication's currentApplication()'s activateWithOptions:(current application's NSApplicationActivateIgnoringOtherApps)
	set returnCode to theAlert's runModal()
	if returnCode = (current application's NSAlertSecondButtonReturn) then error number -128
	
	set (my theResult) to (aMapView's centerCoordinate()) as record
end chooseCoordinate:

-- Internet Connection Check
on hasInternetConnection(aURLString)
	set aURL to |NSURL|'s alloc()'s initWithString:aURLString
	set aReq to NSURLRequest's alloc()'s initWithURL:aURL cachePolicy:(current application's NSURLRequestReloadIgnoringLocalCacheData) timeoutInterval:5.0
	set urlRes to (NSURLConnection's sendSynchronousRequest:aReq returningResponse:(missing value) |error|:(missing value))
	if urlRes = missing value then
		return false
	else
		return true
	end if
end hasInternetConnection

Thanks, this is teaching me a lot!

Multiple results showing now so that is great.

Hmm one issue I’ve just noticed is that even if the image changes on the desktop then the EXIF data returned is always the same so it looks like it’s not returning the data for the right picture some how?

The mapping script works so I just need to work out how to convert the lat / long to radians and enter those in the script.

If the lat / log result was in decimal degrees instead of degrees / minutes then that’d be easy I guess. As it’d be decimal degree x 2*pi I think…

I’ve asked on the ExifTool forum if there is a way of specifying what unit the tool returns the data in.

Learning curve :slight_smile:

The help is greatly appreciated.

Phil did come back with:

exiftool -p “${gpslatitude#;$*=3.14159/180} ${gpslongitude#;$*=3.14159/180}” FILE

But I can’t work out how to revamp that so I can set each into an individual variable?

The example provided by me in the post#13 is not very good. Following is closer to what the OP asked for. To use script the OP should set the aLatitude an aLongitude values. It should be radians. Converting degrees to radians is other task. It is simpler as well. I don’t have test photos of the OP to provide converting workaround.

So, following script (adapted from script of Takaaki Naganoya as well) shows location given latitude and longitude of it:


use AppleScript version "2.5"
use scripting additions
use framework "Foundation"
use framework "AppKit"
use framework "MapKit"
use framework "CoreLocation"

property NSAlert : a reference to current application's NSAlert
property NSString : a reference to current application's NSString
property NSScreen : a reference to current application's NSScreen
property MKMapView : a reference to current application's MKMapView
property MKMapTypeHybrid : a reference to current application's MKMapTypeHybrid
property MKPointAnnotation : a reference to current application's MKPointAnnotation
property MKMapTypeSatellite : a reference to current application's MKMapTypeSatellite
property MKMapTypeStandard : a reference to current application's MKMapTypeStandard
property NSSegmentedControl : a reference to current application's NSSegmentedControl
property NSRunningApplication : a reference to current application's NSRunningApplication
property NSSegmentStyleTexturedRounded : a reference to current application's NSSegmentStyleTexturedRounded
property selSeg : 0
property aMapViewList : {}


set aLatitude to "52.3740"
set aLongitude to "4.8897"
set paramObj to {viewWidth:1000, viewHeight:600, viewSubTitle:"Geolocation Showing Example", viewLat:aLatitude, viewLong:aLongitude}
my performSelectorOnMainThread:"dispMapViewinDifferentScales:" withObject:(paramObj) waitUntilDone:true


on dispMapViewinDifferentScales:paramObj
	set aWidth to (viewWidth of paramObj) as real
	set aHeight to (viewHeight of paramObj) as real
	set aLat to (viewLat of paramObj) as real
	set aLong to (viewLong of paramObj) as real
	--set aTitle to (viewTitle of paramObj) as string
	set aSubTitle to (viewSubTitle of paramObj) as string
	
	set selSeg to 0
	
	--NSViewをつくる
	set aView to current application's NSView's alloc()'s initWithFrame:(current application's NSMakeRect(0, 0, aWidth, aHeight))
	
	--各レベルのMapViewをBoxでつくる
	set wList to {{3, "????World Level Map"}, {5, "????Country Level Map"}, {10, "????City Level Map"}, {17, "????Town Level Map"}}
	set xPos to 0
	repeat with i in wList
		copy i to {aLevelNum, aBoxTitle}
		
		--Boxをつくる
		set aBox to (current application's NSBox's alloc()'s initWithFrame:(current application's NSMakeRect(xPos, 40, aWidth * 0.25, aHeight - 70)))
		(aBox's setTitle:aBoxTitle)
		
		--MapView+Pinをつくる
		set aMapView to makeMKMapView(aWidth * 0.25, aHeight - 70, aLevelNum, aLat, aLong) of me
		
		(aBox's addSubview:aMapView)
		(aView's addSubview:aBox)
		
		set the end of aMapViewList to aMapView
		set xPos to xPos + (aWidth * 0.25)
	end repeat
	
	--Segmented Controlをつくる
	set aSeg to makeSegmentedControl({"Map", "Satellite", "Satellite + Map"}, aWidth, aHeight) of me
	aView's addSubview:aSeg
	
	-- set up alert	
	set theAlert to NSAlert's alloc()'s init()
	tell theAlert
		its setMessageText:""
		its setInformativeText:aSubTitle
		its addButtonWithTitle:"OK"
		its addButtonWithTitle:"Cancel"
		its setAccessoryView:aView
	end tell
	
	-- show alert in modal loop
	NSRunningApplication's currentApplication()'s activateWithOptions:0
	my performSelectorOnMainThread:"doModal:" withObject:(theAlert) waitUntilDone:true
	if (my returnCode as number) = 1001 then error number -128
end dispMapViewinDifferentScales:


on doModal:aParam
	set (my returnCode) to aParam's runModal()
end doModal:



--MKMapViewをつくる
on makeMKMapView(aWidth, aHeight, aZoomLevel, aLat, aLong)
	set aMapView to MKMapView's alloc()'s initWithFrame:(current application's NSMakeRect(0, 0, aWidth, aHeight))
	aMapView's setMapType:(current application's MKMapTypeStandard)
	
	aMapView's setZoomEnabled:true
	aMapView's setScrollEnabled:true
	aMapView's setPitchEnabled:false
	aMapView's setRotateEnabled:false
	aMapView's setShowsCompass:true
	aMapView's setShowsZoomControls:true
	aMapView's setShowsScale:true
	aMapView's setShowsUserLocation:true
	
	set aLocation to current application's CLLocationCoordinate2DMake(aLat, aLong)
	aMapView's setCenterCoordinate:aLocation zoomLevel:aZoomLevel animated:false
	aMapView's setDelegate:me
	
	--MapにPinを追加
	set anAnnotation to current application's MKPointAnnotation's alloc()'s init()
	anAnnotation's setCoordinate:aLocation
	anAnnotation's setTitle:""
	aMapView's addAnnotation:anAnnotation
	
	return aMapView
end makeMKMapView


--Make Segmented Control
on makeSegmentedControl(titleList, aWidth, aHeight)
	set aLen to length of titleList
	
	set aSeg to NSSegmentedControl's alloc()'s init()
	aSeg's setSegmentCount:aLen
	
	set aCount to 0
	repeat with i in titleList
		set j to contents of i
		(aSeg's setLabel:j forSegment:aCount)
		set aCount to aCount + 1
	end repeat
	
	aSeg's setTranslatesAutoresizingMaskIntoConstraints:false
	aSeg's setSegmentStyle:(NSSegmentStyleTexturedRounded)
	aSeg's setFrame:(current application's NSMakeRect(10, 5, 260, 30))
	aSeg's setTrackingMode:0
	aSeg's setTarget:me
	aSeg's setAction:"clickedSeg:"
	aSeg's setSelectedSegment:0
	
	return aSeg
end makeSegmentedControl

--Segmented Control's clicked event handler
on clickedSeg:aSender
	set aSel to aSender's selectedSegment()
	set selSeg to (aSel + 1)
	set mapList to {MKMapTypeStandard, MKMapTypeSatellite, MKMapTypeHybrid}
	set curMap to contents of item selSeg of mapList
	
	repeat with i in aMapViewList
		set aView to contents of i
		(aView's setMapType:(curMap))
	end repeat
end clickedSeg:

That is fantastic! Looks / works really well.

Adding:

-- Created by Hubert
-- https://exiftool.org/forum/index.php?topic=12726.new;topicseen#new
set imageFile to POSIX path of ((choose file) as string)
set gpsCoords to do shell script "usr/local/bin/exiftool " & "'" & imageFile & "'" & " -gpslatitude# -gpslongitude#"
set AppleScript's text item delimiters to ":"
set aLatitude to (text item 2 of paragraph 1 of gpsCoords as number)
set aLongitude to (text item 2 of paragraph 2 of gpsCoords as number)

At the top of the script allows the Latitude / Longitude to be extracted from the selected image and fed through to the rest of the script.

So the only issue to resolve now is finding a working piece of script that can correctly identify the path to the desktop image.

To resolve that I’ve adapted a script that found the correct patch of the desktop picture and opening it in Finder. This script was:

-- https://discussions.apple.com/thread/8373854?answerId=33344100022#33344100022
--
-- Usage: osascript find_wall_pic n

--        n = 1 or 2 (monitor ID)



on replace_chars(this_text, search_string, replacement_string)
	
	-- ref: https://www.macosxautomation.com/applescript/sbrt/sbrt-06.html
	
	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



on run argv
	
	if (count of argv) < 1 then
		
		set screenId to 1
		
	else
		
		set screenId to item 1 of argv as integer
		
	end if
	
	if screenId ≤ 1 then
		
		set screenId to 1 -- 1st monior index
		
	else
		
		set screenId to 18 -- 2nd monitor index
		
	end if
	
	
	
	--        set a to (do shell script "/usr/bin/sqlite3 ~/Library/Application\\ Support/Dock/desktoppicture.db \"SELECT data.value FROM preferences INNER JOIN data on preferences.key=16 and preferences.data_id=data.ROWID where preferences.picture_id =" & screenId & "\"") as string
	
	--        set posixaliaspath to "/Users/kangfucius/Library/Caches/com.apple.preference.desktopscreeneffect.desk top/69677504/DSKPhotosRootSource/" & a
	
	
	
	set posixaliaspath to (do shell script "/usr/bin/sqlite3 ~/Library/Application\\ Support/Dock/desktoppicture.db \"select d1.value || '/' || d2.value from preferences pf1 join data d1 on pf1.data_id=d1.rowid join preferences pf2 on pf1.picture_id=pf2.picture_id join data d2 on pf2.data_id=d2.rowid where pf1.key=10 and pf2.key=16 and pf1.picture_id=" & screenId & "\"") as string
	
	set homepath to (do shell script "echo $HOME")
	
	-- replace "~" in the path to actual $HOME dir
	
	set posixaliaspath to replace_chars(posixaliaspath, "~", homepath)
	
	
	
	set aliaspath to (POSIX file posixaliaspath) as string
	
	set posixpath to POSIX path of aliaspath
	
	set imgfile to POSIX file posixpath
	
	-- tell application "Finder" to reveal imgfile
	
	-- tell application "Finder"
	tell application "Finder"
		
		activate
		
		reveal imgfile
		
	end tell
	
end run

The original script worked perfectly but if I modify and add that at the start of the script as per:

use AppleScript version "2.5"
use scripting additions
use framework "Foundation"
use framework "AppKit"
use framework "MapKit"
use framework "CoreLocation"



-- https://discussions.apple.com/thread/8373854?answerId=33344100022#33344100022
--
-- Usage: osascript find_wall_pic n

--        n = 1 or 2 (monitor ID)



on replace_chars(this_text, search_string, replacement_string)
	
	-- ref: https://www.macosxautomation.com/applescript/sbrt/sbrt-06.html
	
	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



set screenId to 1


--        set a to (do shell script "/usr/bin/sqlite3 ~/Library/Application\\ Support/Dock/desktoppicture.db \"SELECT data.value FROM preferences INNER JOIN data on preferences.key=16 and preferences.data_id=data.ROWID where preferences.picture_id =" & screenId & "\"") as string

--        set posixaliaspath1 to "/Users/kangfucius/Library/Caches/com.apple.preference.desktopscreeneffect.desk top/69677504/DSKPhotosRootSource/" & a



set posixaliaspath to (do shell script "/usr/bin/sqlite3 ~/Library/Application\\ Support/Dock/desktoppicture.db \"select d1.value || '/' || d2.value from preferences pf1 join data d1 on pf1.data_id=d1.rowid join preferences pf2 on pf1.picture_id=pf2.picture_id join data d2 on pf2.data_id=d2.rowid where pf1.key=10 and pf2.key=16 and pf1.picture_id=" & screenId & "\"") as string

set homepath to (do shell script "echo $HOME")

-- replace "~" in the path to actual $HOME dir

set posixaliaspath to replace_chars(posixaliaspath, "~", homepath)



set aliaspath to (POSIX file posixaliaspath) as string

set posixpath to POSIX path of aliaspath

set imgfile to POSIX file posixpath

-- tell application "Finder" to reveal imgfile1

-- tell application "Finder"
-- tell application "Finder"

--	activate

--	reveal imgfile

-- end tell

-- end run


set imageFile to imgfile

-- Created by Hubert =========================================
-- https://exiftool.org/forum/index.php?topic=12726.new;topicseen#new
-- set imageFile to POSIX path of ((choose file) as string)
set gpsCoords to do shell script "usr/local/bin/exiftool " & "'" & imageFile & "'" & " -gpslatitude# -gpslongitude#"
set AppleScript's text item delimiters to ":"
set aLatitude to (text item 2 of paragraph 1 of gpsCoords as number)
set aLongitude to (text item 2 of paragraph 2 of gpsCoords as number)

property NSAlert : a reference to current application's NSAlert
property NSString : a reference to current application's NSString
property NSScreen : a reference to current application's NSScreen
property MKMapView : a reference to current application's MKMapView
property MKMapTypeHybrid : a reference to current application's MKMapTypeHybrid
property MKPointAnnotation : a reference to current application's MKPointAnnotation
property MKMapTypeSatellite : a reference to current application's MKMapTypeSatellite
property MKMapTypeStandard : a reference to current application's MKMapTypeStandard
property NSSegmentedControl : a reference to current application's NSSegmentedControl
property NSRunningApplication : a reference to current application's NSRunningApplication
property NSSegmentStyleTexturedRounded : a reference to current application's NSSegmentStyleTexturedRounded
property selSeg : 0
property aMapViewList : {}


-- set aLatitude to "52.3740"
-- set aLongitude to "4.8897"
set paramObj to {viewWidth:1000, viewHeight:600, viewSubTitle:"Geolocation Showing Example", viewLat:aLatitude, viewLong:aLongitude}
my performSelectorOnMainThread:"dispMapViewinDifferentScales:" withObject:(paramObj) waitUntilDone:true


on dispMapViewinDifferentScales:paramObj
	set aWidth to (viewWidth of paramObj) as real
	set aHeight to (viewHeight of paramObj) as real
	set aLat to (viewLat of paramObj) as real
	set aLong to (viewLong of paramObj) as real
	--set aTitle to (viewTitle of paramObj) as string
	set aSubTitle to (viewSubTitle of paramObj) as string
	
	set selSeg to 0
	
	--NSViewをつくる
	set aView to current application's NSView's alloc()'s initWithFrame:(current application's NSMakeRect(0, 0, aWidth, aHeight))
	
	--各レベルのMapViewをBoxでつくる
	set wList to {{3, "World Level Map"}, {5, "Country Level Map"}, {10, "City Level Map"}, {17, "Town Level Map"}}
	set xPos to 0
	repeat with i in wList
		copy i to {aLevelNum, aBoxTitle}
		
		--Boxをつくる
		set aBox to (current application's NSBox's alloc()'s initWithFrame:(current application's NSMakeRect(xPos, 40, aWidth * 0.25, aHeight - 70)))
		(aBox's setTitle:aBoxTitle)
		
		--MapView+Pinをつくる
		set aMapView to makeMKMapView(aWidth * 0.25, aHeight - 70, aLevelNum, aLat, aLong) of me
		
		(aBox's addSubview:aMapView)
		(aView's addSubview:aBox)
		
		set the end of aMapViewList to aMapView
		set xPos to xPos + (aWidth * 0.25)
	end repeat
	
	--Segmented Controlをつくる
	set aSeg to makeSegmentedControl({"Map", "Satellite", "Satellite + Map"}, aWidth, aHeight) of me
	aView's addSubview:aSeg
	
	-- set up alert    
	set theAlert to NSAlert's alloc()'s init()
	tell theAlert
		its setMessageText:""
		its setInformativeText:aSubTitle
		its addButtonWithTitle:"OK"
		its addButtonWithTitle:"Cancel"
		its setAccessoryView:aView
	end tell
	
	-- show alert in modal loop
	NSRunningApplication's currentApplication()'s activateWithOptions:0
	my performSelectorOnMainThread:"doModal:" withObject:(theAlert) waitUntilDone:true
	if (my returnCode as number) = 1001 then error number -128
end dispMapViewinDifferentScales:


on doModal:aParam
	set (my returnCode) to aParam's runModal()
end doModal:



--MKMapViewをつくる
on makeMKMapView(aWidth, aHeight, aZoomLevel, aLat, aLong)
	set aMapView to MKMapView's alloc()'s initWithFrame:(current application's NSMakeRect(0, 0, aWidth, aHeight))
	aMapView's setMapType:(current application's MKMapTypeStandard)
	
	aMapView's setZoomEnabled:true
	aMapView's setScrollEnabled:true
	aMapView's setPitchEnabled:false
	aMapView's setRotateEnabled:false
	aMapView's setShowsCompass:true
	aMapView's setShowsZoomControls:true
	aMapView's setShowsScale:true
	aMapView's setShowsUserLocation:true
	
	set aLocation to current application's CLLocationCoordinate2DMake(aLat, aLong)
	aMapView's setCenterCoordinate:aLocation zoomLevel:aZoomLevel animated:false
	aMapView's setDelegate:me
	
	--MapにPinを追加
	set anAnnotation to current application's MKPointAnnotation's alloc()'s init()
	anAnnotation's setCoordinate:aLocation
	anAnnotation's setTitle:""
	aMapView's addAnnotation:anAnnotation
	
	return aMapView
end makeMKMapView


--Make Segmented Control
on makeSegmentedControl(titleList, aWidth, aHeight)
	set aLen to length of titleList
	
	set aSeg to NSSegmentedControl's alloc()'s init()
	aSeg's setSegmentCount:aLen
	
	set aCount to 0
	repeat with i in titleList
		set j to contents of i
		(aSeg's setLabel:j forSegment:aCount)
		set aCount to aCount + 1
	end repeat
	
	aSeg's setTranslatesAutoresizingMaskIntoConstraints:false
	aSeg's setSegmentStyle:(NSSegmentStyleTexturedRounded)
	aSeg's setFrame:(current application's NSMakeRect(10, 5, 260, 30))
	aSeg's setTrackingMode:0
	aSeg's setTarget:me
	aSeg's setAction:"clickedSeg:"
	aSeg's setSelectedSegment:0
	
	return aSeg
end makeSegmentedControl

--Segmented Control's clicked event handler
on clickedSeg:aSender
	set aSel to aSender's selectedSegment()
	set selSeg to (aSel + 1)
	set mapList to {MKMapTypeStandard, MKMapTypeSatellite, MKMapTypeHybrid}
	set curMap to contents of item selSeg of mapList
	
	repeat with i in aMapViewList
		set aView to contents of i
		(aView's setMapType:(curMap))
	end repeat
end clickedSeg:

I get error:

So very near to having it working now!

Try following script with your wallpapers.

IMPORTANT: before running the script, make sure the wallpapers will rotated:
1) go System Preferences → Desktop & Screen Saver → Desktop
2) choose folder Favorites of Photos
3) click on some concrete photo from this folder.
4) set checkbox of Change picture, set it to every minute (for example)


use AppleScript version "2.5"
use scripting additions
use framework "Foundation"
use framework "AppKit"
use framework "MapKit"
use framework "CoreLocation"

property NSAlert : a reference to current application's NSAlert
property NSString : a reference to current application's NSString
property NSScreen : a reference to current application's NSScreen
property MKMapView : a reference to current application's MKMapView
property MKMapTypeHybrid : a reference to current application's MKMapTypeHybrid
property MKPointAnnotation : a reference to current application's MKPointAnnotation
property MKMapTypeSatellite : a reference to current application's MKMapTypeSatellite
property MKMapTypeStandard : a reference to current application's MKMapTypeStandard
property NSSegmentedControl : a reference to current application's NSSegmentedControl
property NSRunningApplication : a reference to current application's NSRunningApplication
property NSSegmentStyleTexturedRounded : a reference to current application's NSSegmentStyleTexturedRounded
property selSeg : 0
property aMapViewList : {}

-- get current Pictures folder
tell application "System Events" to set pFldr to pictures folder of current desktop

-- get relative posix path of picture (in the cash)
set POSIXPath to pFldr & "/" & paragraph 1 of (do shell script "ls -tu " & quoted form of pFldr)

-- get full Posix path of current desktop picture
tell application "Finder" to set pictureFileAsAlias to POSIXPath as POSIX file as alias
set currentPicturePOSIXPath to POSIX path of pictureFileAsAlias

set gpsCoords to do shell script "usr/local/bin/exiftool " & "'" & currentPicturePOSIXPath & "'" & " -gpslatitude# -gpslongitude#"
set AppleScript's text item delimiters to ":"
set aLatitude to (text item 2 of paragraph 1 of gpsCoords as number)
set aLongitude to (text item 2 of paragraph 2 of gpsCoords as number)
set AppleScript's text item delimiters to ""

set paramObj to {viewWidth:1000, viewHeight:600, viewSubTitle:"Geolocation Showing Example", viewLat:aLatitude, viewLong:aLongitude}
my performSelectorOnMainThread:"dispMapViewinDifferentScales:" withObject:(paramObj) waitUntilDone:true


on dispMapViewinDifferentScales:paramObj
	set aWidth to (viewWidth of paramObj) as real
	set aHeight to (viewHeight of paramObj) as real
	set aLat to (viewLat of paramObj) as real
	set aLong to (viewLong of paramObj) as real
	--set aTitle to (viewTitle of paramObj) as string
	set aSubTitle to (viewSubTitle of paramObj) as string
	
	set selSeg to 0
	
	--NSViewをつくる
	set aView to current application's NSView's alloc()'s initWithFrame:(current application's NSMakeRect(0, 0, aWidth, aHeight))
	
	--各レベルのMapViewをBoxでつくる
	set wList to {{3, "????World Level Map"}, {5, "????Country Level Map"}, {10, "????City Level Map"}, {17, "????Town Level Map"}}
	set xPos to 0
	repeat with i in wList
		copy i to {aLevelNum, aBoxTitle}
		
		--Boxをつくる
		set aBox to (current application's NSBox's alloc()'s initWithFrame:(current application's NSMakeRect(xPos, 40, aWidth * 0.25, aHeight - 70)))
		(aBox's setTitle:aBoxTitle)
		
		--MapView+Pinをつくる
		set aMapView to makeMKMapView(aWidth * 0.25, aHeight - 70, aLevelNum, aLat, aLong) of me
		
		(aBox's addSubview:aMapView)
		(aView's addSubview:aBox)
		
		set the end of aMapViewList to aMapView
		set xPos to xPos + (aWidth * 0.25)
	end repeat
	
	--Segmented Controlをつくる
	set aSeg to makeSegmentedControl({"Map", "Satellite", "Satellite + Map"}, aWidth, aHeight) of me
	aView's addSubview:aSeg
	
	-- set up alert	
	set theAlert to NSAlert's alloc()'s init()
	tell theAlert
		its setMessageText:""
		its setInformativeText:aSubTitle
		its addButtonWithTitle:"OK"
		its addButtonWithTitle:"Cancel"
		its setAccessoryView:aView
	end tell
	
	-- show alert in modal loop
	NSRunningApplication's currentApplication()'s activateWithOptions:0
	my performSelectorOnMainThread:"doModal:" withObject:(theAlert) waitUntilDone:true
	if (my returnCode as number) = 1001 then error number -128
end dispMapViewinDifferentScales:


on doModal:aParam
	set (my returnCode) to aParam's runModal()
end doModal:



--MKMapViewをつくる
on makeMKMapView(aWidth, aHeight, aZoomLevel, aLat, aLong)
	set aMapView to MKMapView's alloc()'s initWithFrame:(current application's NSMakeRect(0, 0, aWidth, aHeight))
	aMapView's setMapType:(current application's MKMapTypeStandard)
	
	aMapView's setZoomEnabled:true
	aMapView's setScrollEnabled:true
	aMapView's setPitchEnabled:false
	aMapView's setRotateEnabled:false
	aMapView's setShowsCompass:true
	aMapView's setShowsZoomControls:true
	aMapView's setShowsScale:true
	aMapView's setShowsUserLocation:true
	
	set aLocation to current application's CLLocationCoordinate2DMake(aLat, aLong)
	aMapView's setCenterCoordinate:aLocation zoomLevel:aZoomLevel animated:false
	aMapView's setDelegate:me
	
	--MapにPinを追加
	set anAnnotation to current application's MKPointAnnotation's alloc()'s init()
	anAnnotation's setCoordinate:aLocation
	anAnnotation's setTitle:""
	aMapView's addAnnotation:anAnnotation
	
	return aMapView
end makeMKMapView


--Make Segmented Control
on makeSegmentedControl(titleList, aWidth, aHeight)
	set aLen to length of titleList
	
	set aSeg to NSSegmentedControl's alloc()'s init()
	aSeg's setSegmentCount:aLen
	
	set aCount to 0
	repeat with i in titleList
		set j to contents of i
		(aSeg's setLabel:j forSegment:aCount)
		set aCount to aCount + 1
	end repeat
	
	aSeg's setTranslatesAutoresizingMaskIntoConstraints:false
	aSeg's setSegmentStyle:(NSSegmentStyleTexturedRounded)
	aSeg's setFrame:(current application's NSMakeRect(10, 5, 260, 30))
	aSeg's setTrackingMode:0
	aSeg's setTarget:me
	aSeg's setAction:"clickedSeg:"
	aSeg's setSelectedSegment:0
	
	return aSeg
end makeSegmentedControl

--Segmented Control's clicked event handler
on clickedSeg:aSender
	set aSel to aSender's selectedSegment()
	set selSeg to (aSel + 1)
	set mapList to {MKMapTypeStandard, MKMapTypeSatellite, MKMapTypeHybrid}
	set curMap to contents of item selSeg of mapList
	
	repeat with i in aMapViewList
		set aView to contents of i
		(aView's setMapType:(curMap))
	end repeat
end clickedSeg:

I agree that looks better, and should work, but…

-- get full Posix path of current desktop picture
tell application "Finder" to set pictureFileAsAlias to POSIXPath as POSIX file as alias
set currentPicturePOSIXPath to POSIX path of pictureFileAsAlias

This always results in the same location being shown on the map, which is NOT location contained within the photograph in use on the desktop in the rotation which has been set.

The script I posted earlier (see below) does always find the right picture:

-- https://discussions.apple.com/thread/8373854?answerId=33344100022#33344100022
--
-- Usage: osascript find_wall_pic n

--        n = 1 or 2 (monitor ID)



on replace_chars(this_text, search_string, replacement_string)
	
	-- ref: https://www.macosxautomation.com/applescript/sbrt/sbrt-06.html
	
	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



on run argv
	
	if (count of argv) < 1 then
		
		set screenId to 1
		
	else
		
		set screenId to item 1 of argv as integer
		
	end if
	
	if screenId ≤ 1 then
		
		set screenId to 1 -- 1st monior index
		
	else
		
		set screenId to 18 -- 2nd monitor index
		
	end if
	
	
	
	--        set a to (do shell script "/usr/bin/sqlite3 ~/Library/Application\\ Support/Dock/desktoppicture.db \"SELECT data.value FROM preferences INNER JOIN data on preferences.key=16 and preferences.data_id=data.ROWID where preferences.picture_id =" & screenId & "\"") as string
	
	--        set posixaliaspath to "/Users/kangfucius/Library/Caches/com.apple.preference.desktopscreeneffect.desk top/69677504/DSKPhotosRootSource/" & a
	
	
	
	set posixaliaspath to (do shell script "/usr/bin/sqlite3 ~/Library/Application\\ Support/Dock/desktoppicture.db \"select d1.value || '/' || d2.value from preferences pf1 join data d1 on pf1.data_id=d1.rowid join preferences pf2 on pf1.picture_id=pf2.picture_id join data d2 on pf2.data_id=d2.rowid where pf1.key=10 and pf2.key=16 and pf1.picture_id=" & screenId & "\"") as string
	
	set homepath to (do shell script "echo $HOME")
	
	-- replace "~" in the path to actual $HOME dir
	
	set posixaliaspath to replace_chars(posixaliaspath, "~", homepath)
	
	
	
	set aliaspath to (POSIX file posixaliaspath) as string
	
	set posixpath to POSIX path of aliaspath
	
	set imgfile to POSIX file posixpath
	
	-- tell application "Finder" to reveal imgfile
	
	-- tell application "Finder"
	tell application "Finder"
		
		activate
		
		reveal imgfile
		
	end tell
	
end run

this runs within keyboard maestro and it opens a Finder window selecting the correct image file which is set as the desktop picture.

The output from the script I reference is:

Macintosh HD:Users:dbrewood:Pictures:Photos Library.photoslibrary:originals:5:59D5C6A1-E973-4CD8-83DE-B092E0064855.jpeg

Which when passed to Finder opens the picture correctly.

I guess this:

set posixaliaspath to (do shell script "/usr/bin/sqlite3 ~/Library/Application\\ Support/Dock/desktoppicture.db \"select d1.value || '/' || d2.value from preferences pf1 join data d1 on pf1.data_id=d1.rowid join preferences pf2 on pf1.picture_id=pf2.picture_id join data d2 on pf2.data_id=d2.rowid where pf1.key=10 and pf2.key=16 and pf1.picture_id=" & screenId & "\"") as string

set homepath to (do shell script "echo $HOME")

-- replace "~" in the path to actual $HOME dir

set posixaliaspath to replace_chars(posixaliaspath, "~", homepath)


set aliaspath to (POSIX file posixaliaspath) as string

set posixpath to POSIX path of aliaspath

set imgfile to POSIX file posixpath

Needs changing to generate something like:

Macintosh HD\Users\dbrewood\Pictures\Photos Library.photoslibrary:originals\5:59D5C6A1-E973-4CD8-83DE-B092E0064855.jpeg

I’ve tried adding in:

set AppleScript's text item delimiters to "\"

to change the : to \ but it gives an error…