alanhe421 / alfred-workflows

Save time, Improve life.🚀 ☕️ 💻
https://medium.com/@alanhe421/list/alfred-a65a11fa7a0f
MIT License
645 stars 61 forks source link

[Bug]: About this Mac issue with Model #330

Closed andypiper closed 1 year ago

andypiper commented 1 year ago

Describe the bug

The About action is showing a strange error in the row for Model, with XML output.

Screenshot 2023-02-25 at 12 13 59
[11:53:22.685] About Mac[Script Filter] Queuing argument '(null)'
[11:53:23.310] About Mac[Script Filter] Script with argv '(null)' finished
[11:53:23.314] About Mac[Script Filter] {
    "items": [
{"title":"Andy Piper","subtitle":"User Name","icon":{"path":"icons/user.png"},"arg":"Andy Piper","uid":"user_name","text":{"copy":"Andy Piper","largetype":"Andy Piper"}},
{"title":"zhalen.lan","subtitle":"Host Name","icon":{"path":"./icons/hostname.png"},"arg":"zhalen.lan","uid":"host_name","text":{"copy":"zhalen.lan","largetype":"zhalen.lan"}},
{"title":"f8:4d:89:69:f9:41","subtitle":"Primary Ethernet Address","icon":{"path":"./icons/ethernet.png"},"arg":"f8:4d:89:69:f9:41","uid":"primary__ethernet__address","text":{"copy":"f8:4d:89:69:f9:41","largetype":"f8:4d:89:69:f9:41"}},
{"title":"<?xml version=1.0 encoding=utf-8 ?><root><error>0009</error><locale>en_US</locale></root>","subtitle":"Model","icon":{"path":"./icons/model.png"},"arg":"<?xml version=1.0 encoding=utf-8 ?><root><error>0009</error><locale>en_US</locale></root>","uid":"model","text":{"copy":"<?xml version=1.0 encoding=utf-8 ?><root><error>0009</error><locale>en_US</locale></root>","largetype":"<?xml version=1.0 encoding=utf-8 ?><root><error>0009</error><locale>en_US</locale></root>"}},
{"title":"172.31.0.215","subtitle":"IPv4 Address","icon":{"path":"./icons/ip.png"},"arg":"172.31.0.215","uid":"ipv4_address","text":{"copy":"172.31.0.215","largetype":"172.31.0.215"},"match":"ip_"},
{"title":"Ventura 13.2.1","subtitle":"MacOS System Version","icon":{"path":"./icons/mac.png"},"arg":"Ventura 13.2.1","uid":"mac_os_system_version","text":{"copy":"Ventura 13.2.1","largetype":"Ventura 13.2.1"},"match":"os Ventura 13.2.1 "},
{"title":"ARM64E","subtitle":"CPU Type","icon":{"path":"./icons/cpu.png"},"arg":"ARM64E","uid":"cpu_type","text":{"copy":"ARM64E","largetype":"ARM64E"}},
{"title":"32 GB Total , 0 GB Free","subtitle":"Physical Memory, 0% Free","icon":{"path":"./icons/memory.png"},"arg":"32GB total, 0GB free","uid":"physical_memory","text":{"copy":"32GB total, 0GB free","largetype":"32GB total, 0GB free"}},
{"title":"995 GB Total , 260 GB Free","subtitle":"Physical Disk(startup), 26.1% Free","icon":{"path":"./icons/disk.png"},"arg":"995GB total,260GB free","uid":"physical__disk","text":{"copy":"995GB total,260GB free","largetype":"995GB total,260GB free"}},
{"title":"Locale / Language","subtitle":"en_GB","icon":{"path":"./icons/locale.png"},"arg":"en_GB","uid":"locale_language","text":{"copy":"en_GB","largetype":"en_GB"}},
{"title":"Display Resolution","subtitle":"3024 x 1964","icon":{"path":"./icons/display-resolution.png"},"arg":"3024 x 1964","uid":"display_resolution","text":{"copy":"3024 x 1964","largetype":"3024 x 1964"}}
 ]
}

Workflow Name

About Mac

Alfred Version

5.0.6

MacOS Version

macOS 13 Ventura

MacOS Locale

EN

alanhe421 commented 1 year ago

I have updated the workflow, just have a try.

image

if the model error occurs, assign any keyword and clean the cache.

image

thank you.

andypiper commented 1 year ago

I'm seeing workflow v1.11 and this is not working for me at the moment (I tried deleting and reinstalling the workflow), thanks for looking into this, I'll try again in a few days in case there's an issue in getting an updated version.

alanhe421 commented 1 year ago

ok. image https://github.com/alanhg/alfred-workflows/tree/master/about-mac

andypiper commented 1 year ago

This is not showing in the Alfred Gallery, so I downloaded the workflow from GitHub and installed. I also cleaned the cache.

I am still seeing this problem with the value for Model.

[10:26:50.567] About Mac[Script Filter] {
    "items": [
{"title":"Andy Piper","subtitle":"User Name","icon":{"path":"icons/user.png"},"arg":"Andy Piper","uid":"user_name","text":{"copy":"Andy Piper","largetype":"Andy Piper"}},
{"title":"zhalen.lan","subtitle":"Host Name","icon":{"path":"./icons/hostname.png"},"arg":"zhalen.lan","uid":"host_name","text":{"copy":"zhalen.lan","largetype":"zhalen.lan"}},
{"title":"f8:4d:89:69:f9:41","subtitle":"Primary Ethernet Address","icon":{"path":"./icons/ethernet.png"},"arg":"f8:4d:89:69:f9:41","uid":"primary__ethernet__address","text":{"copy":"f8:4d:89:69:f9:41","largetype":"f8:4d:89:69:f9:41"}},
{"title":"<?xml version=1.0 encoding=utf-8 ?><root><error>0009</error><locale>en_US</locale></root>","subtitle":"Model","icon":{"path":"./icons/model.png"},"arg":"<?xml version=1.0 encoding=utf-8 ?><root><error>0009</error><locale>en_US</locale></root>","uid":"model","text":{"copy":"<?xml version=1.0 encoding=utf-8 ?><root><error>0009</error><locale>en_US</locale></root>","largetype":"<?xml version=1.0 encoding=utf-8 ?><root><error>0009</error><locale>en_US</locale></root>"}},
{"title":"172.31.0.215","subtitle":"IPv4 Address","icon":{"path":"./icons/ip.png"},"arg":"172.31.0.215","uid":"ipv4_address","text":{"copy":"172.31.0.215","largetype":"172.31.0.215"},"match":"ip_"},
{"title":"Ventura 13.2.1","subtitle":"MacOS System Version","icon":{"path":"./icons/mac.png"},"arg":"Ventura 13.2.1","uid":"mac_os_system_version","text":{"copy":"Ventura 13.2.1","largetype":"Ventura 13.2.1"},"match":"os Ventura 13.2.1 "},
{"title":"ARM64E","subtitle":"CPU Type","icon":{"path":"./icons/cpu.png"},"arg":"ARM64E","uid":"cpu_type","text":{"copy":"ARM64E","largetype":"ARM64E"}},
{"title":"32 GB Total , 0 GB Free","subtitle":"Physical Memory, 0% Free","icon":{"path":"./icons/memory.png"},"arg":"32GB total, 0GB free","uid":"physical_memory","text":{"copy":"32GB total, 0GB free","largetype":"32GB total, 0GB free"}},
{"title":"995 GB Total , 292 GB Free","subtitle":"Physical Disk(startup), 29.3% Free","icon":{"path":"./icons/disk.png"},"arg":"995GB total,292GB free","uid":"physical__disk","text":{"copy":"995GB total,292GB free","largetype":"995GB total,292GB free"}},
{"title":"Locale / Language","subtitle":"en_GB","icon":{"path":"./icons/locale.png"},"arg":"en_GB","uid":"locale_language","text":{"copy":"en_GB","largetype":"en_GB"}},
{"title":"Display Resolution","subtitle":"3024 x 1964","icon":{"path":"./icons/display-resolution.png"},"arg":"3024 x 1964","uid":"display_resolution","text":{"copy":"3024 x 1964","largetype":"3024 x 1964"}}
 ]
}
andypiper commented 1 year ago

I'm looking at the code. I am not able to make a successful call to https://support-sp.apple.com/ to retrieve the model information. Is this a valid way to check the Mac model?

andypiper commented 1 year ago

I had a look around GitHub for similar code, and I don't know what the reason is, but this network call is not working to retrieve the model information for this M1 Pro MacBook. I've also confirmed that it is not an ad blocker or other network issue - the curl call is definitely reaching the Apple server, but the response is always an error in the XML document.

andypiper commented 1 year ago

You might need to fall back to the standard model information (MacBookPro18,3 in this case)

andypiper commented 1 year ago

This pull request may be helpful. This works for me (but I don't know if this works universally)

/usr/libexec/PlistBuddy -c "print 0:product-description" /dev/stdin <<< $(/usr/sbin/ioreg -abr -k "product-name")
MacBook Pro (14-inch, 2021)
alanhe421 commented 1 year ago
  1. PlistBuddy not work on my macMacBook Pro (16-inch, 2019) image
  2. just have run the following command?
    
    SN=$(system_profiler SPHardwareDataType | awk '/Serial/ {print $4}')

curl https://support-sp.apple.com/sp/product\?cc\=${SN: -4} --silent | sed 's|.(.).*|\1|'



paste the output, please.

![image](https://user-images.githubusercontent.com/9245110/221577440-c5d1bc45-a884-4580-8ef4-58b601e556bb.png)
andypiper commented 1 year ago

I just ran that command and see the same output that is happening in the workflow:

<?xml version="1.0" encoding="utf-8" ?><root><error>0009</error><locale>en_US</locale></root>

The new Macs have randomised serial numbers and this web API call no longer works.

Plistbuddy exists on older Macs but I guess the product description key is not available in (maybe non-Apple Silicon?) Macs? I do not know for sure.

🙁

alanhe421 commented 1 year ago
  1. I test m1 ok after run the command
  2. paste command and run in terminal instead of workflow.
vitorgalvao commented 1 year ago

I have updated the workflow, just have a try.

Updates to the workflow aren’t immediately reflected in the Gallery. This is by design, so they can go under review again and give you time to iron out kinks, like in this situation where it turns out it wasn’t yet fixed.

The latest update in particular has a major issue: you’re doing rm -rf $alfred_workflow_cache/** which is dangerous! You have to quote your variables or they’ll split on spaces and you can potentially erase more than intended. The double asterisk also reaches for more than necessary.

The correct code would be rm -rf "${alfred_workflow_cache}" or better yet use the Automation Task Files and Folders → Send to Trash which at least gives the user the chance to recover the files.

alanhe421 commented 1 year ago

@vitorgalvao

I think you are right, I changed the cleaning method. update the workflow. image

image

thank you.

vitorgalvao commented 1 year ago

But does cleaning the cache work? Wasn’t that added to fix this issue but turns out it didn’t fix it? Caches are per-Mac and a Mac’s designation won’t change, so cleaning the cache shouldn’t have an effect.

If that change was added to solve a problem but it didn’t solve it, do you still want to release it?

alanhe421 commented 1 year ago

@vitorgalvao

  1. trigger the clean keyword
  2. trigger about workflow can you have a try? I test ok.

I think the issue is fixed. I think @andypiper did not clean the cache.

vitorgalvao commented 1 year ago

trigger the clean keyword

There is no keyword in that, it is empty. Also, the title is all in lowercase. Please don’t rush, there is time to do things slowly and right.

alanhe421 commented 1 year ago

trigger the clean keyword

There is no keyword in that, it is empty. Also, the title is all in lowercase. Please don’t rush, there is time to do things slowly and right.

I think it's just a workaround for any issue - user. Not everyone needs it.

So I set no keyword.

vitorgalvao commented 1 year ago

If there’s no keyword, then there’s no way to trigger it. If there’s no way to trigger it, then there’s no point in having it.

If you have to teach a user to set a keyword to run that, might as well just tell them to open the cache directory in the Finder and delete it. It would be faster and less confusing.

You could instead make a modifier in the main keyword, for example. So when a user does it clears the cache.

alanhe421 commented 1 year ago

OK. I set it. Set up a combination hotkey so that the simple hotkeys are preserved for future function expansion.

@vitorgalvao

image

image

image

vitorgalvao commented 1 year ago

Set up a combination hotkey so that the simple hotkeys are preserved for future function expansion.

Good call!

Thank you for the fast changes. Update will be live later today.

alanhe421 commented 1 year ago

@vitorgalvao Thank you for your help too.

andypiper commented 1 year ago

Using 1.13 from the gallery on Ventura on an M1 Pro MacBook Pro still demonstrates the same issue with the Model output as originally reported - I've cleaned the cache using the workflow, I also tried uninstalling and reinstalling the workflow, same result.

alanhe421 commented 1 year ago

Using 1.13 from the gallery on Ventura on an M1 Pro MacBook Pro still demonstrates the same issue with the Model output as originally reported - I've cleaned the cache using the workflow, I also tried uninstalling and reinstalling the workflow, same result.

hotkey to clean cache in the latest workflow?

andypiper commented 1 year ago

no, does not work with the clean cache hotkey, or manually removing the plugin and cache and reinstalling 😞 never mind.