Wednesday, February 14, 2024

AppleScript to very slowly list the albums a macOS Photos.app image is associated with

macOS Photos.app does not give users a way to identify which albums contain a selected photo. I found a relatively current AppleScript that works in Ventura; in our broken world there's no repository for these things so I've copied it below. You can select a photos then run the script in ScriptEditor or Export as application and run after selecting an image. On a 2023 Air with a large complex library it takes about 40 seconds to show results.

If you wish you can wrap the AppleScript in a Shortcuts.app Shortcut and from there configure it to show in the Ventura Services menu (all shortcuts can appear there).
 
Please submit a feedback request to Apple. Obviously Photos.app should support this function. Sadly, I suspect Apple goes by its usage data and has learned that most users of Photos do not use or create Albums -- or add any kind of metadata to images. So it will probably never be fixed.

Source: https://discussions.apple.com/docs/DOC-250005659
Author: Jacques Rioux, leonie

-- Jacques Rioux's script  https://discussions.apple.com/message/29601534#29601534

-- modified by leonie for Catalina

--  version 1.01, changed a dialog to a notification

-- version 2, added the support to suppress smart albums


-- Select the photo in Photos, then run this script 

-- by pressing the "Run" button in the script editor 

-- or run it from the scripts menu.

-- The script will show first a panel with the filename of the photo it is searching for.

-- Then it will show a second panel with the list of albums. 

-- if you do not see the panels, click the script Editor icon in the Dock, if it is bouncing.


global allalbums -- the list of all albums

global allfolders -- the list of all folders



set NoSmartAlbums to true -- set this to false, if you want to find the smart albums too


--part 1. get the selected photos

tell application "Photos"

activate

-- Add the photo you want to search for to a top level album as the first item in the album

set resultcaption to "Searching for: "

try

set sel to selection

if sel is {} then error "The selection  is empty" -- no selection 

on error errTexttwo number errNumtwo

display dialog "No photos selected " & errNumtwo & return & errTexttwo

return

end try

set imagename to "unknown filename"

try

set target to item 1 of sel -- the image to seach for

tell target

set imagename to the filename of target

end tell

on error errTexttwo number errNumtwo

display dialog "Cannot get the filename of the first image: " & errNumtwo & return & errTexttwo

end try

set resultcaption to (resultcaption & imagename)

end tell



display notification resultcaption subtitle imagename


-- Part 2: get a list of all albums by searching the nested folders

set allfolders to {}

set allalbums to {}



tell application "Photos"

set allalbums to the albums --  collect all albums

set allfoldernames to {}

set allalbumnames to {}

set level to 0 -- nesting level of folders

set nextlevelFolders to the folders

set currentLevelFolders to {}

repeat while (nextlevelFolders is not {})

set currentLevelFolders to nextlevelFolders

set nextlevelFolders to {}

repeat with fi in currentLevelFolders

tell fi

set ffolders to its folders

set falbums to its albums

set nextlevelFolders to ffolders & nextlevelFolders

set allalbums to falbums & allalbums

end tell

end repeat

set allfolders to currentLevelFolders & allfolders

set level to level + 1

end repeat

-- return allalbums --test

end tell


-- removing albums with "smart" in the name

if NoSmartAlbums then

set without_smart_Albums to {}

repeat with a in allalbums

if (the name of a does not contain "smart") then set without_smart_Albums to {a} & without_smart_Albums

end repeat

set allalbums to without_smart_Albums -- to exclude smart albums 

end if


-- From Jacques Rioux's script:

tell application "Photos"

if sel is {} then return -- no selection 

try

set thisId to id of item 1 of sel

on error errText number errNum

display dialog "Error: cannot get the image ID" & errNum & return & errText & "Trying again"

try

delay 1

set thisId to id of item 1 of sel

on error errTexttwo number errNumtwo

display dialog "Skipping image due to repeated error: " & errNumtwo & return & errTexttwo

error "giving up"

return

end try --second attempt

end try

set theseNames to {}

repeat with a in allalbums

try

tell a

if ((the id of media items) contains thisId) then

set theseNames to {the name of a} & theseNames

end if

end tell

--set theseNames to name of (albums whose id of media items contains thisId)

on error errText number errNum

display dialog "Error: cannot get the albums" & errNum & return & errText & "Trying again"

try

delay 1

tell a

if ((the id of media items) contains thisId) then

set theseNames to {the name of a} & theseNames

end if

end tell

on error errTexttwo number errNumtwo

display dialog "Skipping image due to repeated error: " & errNumtwo & return & errTexttwo

error "giving up"

return

end try

end try

end repeat

end tell


if theseNames is not {} then

set {oTid, text item delimiters} to {text item delimiters, return}

set {t, text item delimiters} to {theseNames as string, oTid}

-- return oTid

else

set t to "No album"

end if

activate


set resultcaption to resultcaption & ", found it in these albums:

" & t as string

set the clipboard to resultcaption

display notification resultcaption subtitle "Saved to the Clipboard"


display dialog resultcaption & ", Saved to the Clipboard" buttons {"OK"} default button "OK"

-- you can press the Enter key or the return Key to close the dialog

return resultcaption -- léonie

Wednesday, January 17, 2024

Not receiving SMS two factor authentication codes for Facebook, Instagram, others: remove blocked numbers

A friend was not receiving Facebook SMS two factor authentication codes on his iPhone. I removed all his blocked numbers and he received the code. We assume he accidentally blocked the number Facebook uses to send SMS codes.

You can see blocked numbers in Settings:Phone:Blocked Contacts (it's actually a list of blocked numbers, not a list of blocked Contacts). If iCloud sync is working you see the same list in Messages on macOS.

Tuesday, January 09, 2024

Google Account without Google email that routes email to a Google Workspace address

My son has an email address of the form tim@familyname.com where familyname.com is a pseudonym for a domain I own with legacy free Google Apps (now Workspace) accounts.

He also has a Google Account with the Google Account ID of tim@familyname.com. I think he created it somehow with YouTube. (He has a cognitive disability which doesn't stop him from doing some weird shit I can't figure out.)

His second Google Account does not have the email address of tim@familyname.com because that belongs to the Google Workspace account. Instead of it has an email of the form: tim%familyname.com@gtempaccount.com. If I send email to that gtempaccount.com address it redirects to tim@familyname.com.

This feels like a security risk waiting to be exploited. It certainly is weird. It reminds me that Google Workspace accounts don't have the same meaning and privileges as full Google @gmail.com accounts.




Saturday, January 06, 2024

Rendering ChatGPT output in readable form in a Juypter Notebook

Update: This post is still useful, but there's also a way to enable line wrap in Visual Studio Code's Jupyter extension. You can also use the Python Print function instead of the Display example in my original post. For example:

output = client.completions.create(
    model="gpt-3.5-turbo-instruct",
    prompt="List the days of the week: ",
    max_tokens=100,
    stop = "Saturday", #put this in for fun
)
print(output.choices[0].text)

Note these print parameters are specific to this particular object's structure. (I think JSON but I'm a newbie.)

Original below
--------

This was a bit of a revelation. I don't know Python but I've been working through a ChatGPT / LLM tutorial using Visual Studio Code and a Juypter Notebook on macOS. In a Jupyter cell the output renders below the cell and it looks like this:

Completion(id='cmpl-....', choices=[CompletionChoice(finish_reason='stop', index=0, logprobs=None, text='1...

All in one unreadable line with \n as a paragraph deliver and no line wrap.

I asked ChatGPT 4 to help. Over a series of interactions I tried different things and got various error messages I passed to ChatGPT 4. In turn it analyzed my error message and suggested fixes.

This is what I ended up with in about 15 minutes, here added to a cell that ran a simple prompt query

from IPython.display import display, HTML

output = client.completions.create(

    model="gpt-3.5-turbo-instruct",

    prompt="write me a poem",

    max_tokens=100,

    n=3

)

text_content = output.choices[0].text if output.choices else ""

html_output = text_content.replace('\n', '<br>')

display(HTML(html_output))

This is what the output looks like now (the poetry is greeting card quality and mildly painful):

A poem, a weave of words and rhyme

A tapestry of thoughts and time

A magic spell from the poet's pen

A story of love, of loss, of when


The stars above, they guide my hand

As I write of distant lands

Of fiery sunsets and ocean tides

Of moments we hold and let slip by ...   

[Adolescent poetry truncated] 

This screenshot shows it best ...


We are in a new world.

Wednesday, January 03, 2024

Photos lethal bug: non-repairable library corruption when click on Shared Album changes for standalone library, "The library could not be opened"

Nobody asks an Apple customer user why they despise Apple. There are so many reasons.

My latest reason to hate Apple is a bug in Ventura 13.6.1 Photos.app.

Click on Shared Album Activity for a standalone non-primary library and Photos crashes immediately.

After that when trying to open Photos.app initiates Library Repair -- but the repair fails with this unhelpful error message:


At this point I have only a dull Apple hatred because Apple's Aperture migration fiasco killed my hate glands.

After doing an option-command launch of the broken library macOS Ventura Photos.app first does a repair then does a full "Recovery". This takes a while but in my case it worked.

Don't click that Activity link.

Caveat: Monterey Photos.app failed to convert my Aperture Library so the conversion was done with Power Photos. So my Library may have some anomalies from that history.


Friday, December 22, 2023

Retiring domain associated with a DreamHost WordPress site - migrating site content to a new domain

I recently decided not to renew a domain managed and registered with DreamHost. That domain had an associated WordPress site. This is the sequence I followed to preserve the content of the site.

  1. Turned off renewal for the domain (domain_old).
  2. In WordPress for domain_old I exported the site as a XML file which I downloaded and archived.
  3. In DreamHost control panel Manage Websites I clicked "new website". This let me add a subdomain to one of my existing domains.
  4. In DreamHost control panel Manage Websites I clicked on domain_old and scrolled down to entry for Domain. That says "change your WordPress site to run under a different domain name". I chose the subdomain I created earlier. This took about 5-10 minutes to run.
  5. When I then visited the subdomain I created the WordPress site came up.
The process only took a few minutes the first time I tried.

Tuesday, December 19, 2023

Downloading Facebook posts to document a trip

During a recent trip to Seoul South Korea I did a travelogue through Facebook posts about the odd sorts of things that interest me. I wanted to get them into a folder where I'm storying notes and information about the trip.

I found this worked reasonably well:

  1. Follow Facebook's directions for downloading a copy of Facebook data.
  2. Specify posts and the date range you want. If time zones are a factor you may want to go a day beyond what you'd expect. (The first download range ended Dec 15 when we left Korea, but that last day was not in the download. I suspect a time zone bug. I did it again specifying Dec 16.)
  3. Specify HTML as a format and highest resolution images
I was notified the download was ready after about 30 minutes or so. The downloaded archive pages rendered in my browser. It's not a pretty layout but it has my text and images and comments on the images. It didn't include comments on the posts.