Open ke6yjc opened 1 year ago
There isn't a particular trick, no. Sent messages should display the same as received messages. Does this happen in all conversations?
Also, if you're looking to move chats into CRM, Mouseless Messenger may not be the most ideal option. You might consider iMessage Exporter, which queries the Messages database in a much deeper way than Mouseless Messenger.
Ha! I just upgraded my system to the latest version of Ventura, and now I see it.
I'll investigate and start working on a fix.
So not sure if this is really anything on your side. I started digging into the database and found that the values in the database are NULL it looks like. You can see in the preview below there is a message missing that I sent. This directly correlates to ROWID 202555 I think. Maybe something changed in the DB where the entry is stored?
If I look in iMessage on any device all of the messages are there, weird.
Apple seem to have modified the schema such that the message body for sent messages now gets stored in the attributedBody
column. The column's content is a serialized NSAttributedString
— packed using NSArchiver
.
It's taken me the better part of this morning, but the message body can be extracted like so:
#!/usr/bin/env osascript -l JavaScript
function run(argv) {
const App = Application.currentApplication();
App.includeStandardAdditions = true;
ObjC.bindFunction('malloc', ['void *', ['int']]);
const BLOB_QUERY = `\
SELECT HEX(message.attributedBody)
FROM (
SELECT message_id, chat_id, ROW_NUMBER() \
OVER ( \
PARTITION BY chat_id \
ORDER BY message_id DESC \
) AS row_num \
FROM chat_message_join \
WHERE chat_id IN ( \
SELECT chat_id \
FROM chat_message_join \
WHERE message_id IN ( \
SELECT MAX(message_id) \
FROM chat_message_join \
GROUP BY chat_id \
ORDER BY message_id DESC \
LIMIT 1
)
)
) chat_message_join \
JOIN message ON chat_message_join.message_id = message.ROWID \
JOIN chat ON chat_message_join.chat_id = chat.ROWID \
WHERE row_num < 2
ORDER BY message_id DESC`;
const SQLITE_COMMAND = `sqlite3 \
~/Library/Messages/chat.db "${BLOB_QUERY}"`;
const result = App.doShellScript(SQLITE_COMMAND);
const bytes = [];
for (let c = 0; c < result.length; c += 2)
bytes.push(parseInt(result.substr(c, 2), 16));
const $bytes = $.malloc(bytes.length);
for (let i = 0; i < bytes.length; i++) {
$bytes[i] = bytes[i];
}
const msgBody = $.NSUnarchiver.alloc
.initForReadingWithData($.NSData.dataWithBytesLength($bytes, bytes.length))
.decodeTopLevelObjectAndReturnError(0).string;
return ObjC.unwrap(msgBody);
}
This example uses a modified version of the existing SQL but only grabs the most recent message for testing. Please feel free to paste it into Script Editor and try it out. If it works, I can work on releasing a patch.
Yup, it seems to have done the trick!
SYSTEM01 ~ % ./test.js
This is a test and only a test... 1 2 3
SYSTEM01 ~ %
Thanks for testing that! I'll get this patched.
It'll be a good opportunity to repackage/re-factor for Alfred Gallery, too.
I've got an update almost ready for this. It'll also include a PDF/HTML export feature.
This issue should now be fixed in the latest release.
Overall AWESOME update!! Here are my results from testing v2.0. Hope the feedback helps.
I tried the latest version and it does not seem to work until I did some tweaking. I'm sure the issue will be easy for you to figure out, but my program hacking skills are failing me. lol
When I press command+space and type msg it appears to bomb out. I looked in the debugger and it shows an invalid usage of the 'date' command I believe.
[20:21:58.268] Mouseless Messenger[Script Filter] Queuing argument '(null)'
[20:21:58.907] Mouseless Messenger[Script Filter] Script with argv '(null)' finished
[20:21:58.911] ERROR: Mouseless Messenger[Script Filter] Code 1: /Users/demouser/Library/Caches/com.runningwithcrayons.Alfred/Workflow Scripts/8609C814-EB38-4164-97B1-8698EA815B3F: execution error: Error: Error: usage: date [-jnRu] [-r seconds|file] [-v[+|-]val[ymwdHMS]]
[-I[date | hours | minutes | seconds]]
[-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format] (1)
line 641 seems to be giving the fits as if I remove everything in-between the backticks I can get it to work. I tried to play with the syntax via terminal and while it seems correct it's complaining about an execution error.
After that tweak I was able to get it to run. Not sure if this is how it's supposed to look?
one other bug I found is if you click shit to preview and then press return it crashes Alfred.
Small feature request would be to map control + enter (when previewing) to copy the preview into the clipboard in plain text w/ time stamps if possible.
Thank you for the bug reports and for the coffee purchases! I really appreciate it.
My guess is that Alfred doesn't actually generate a workflow's preferences property list until the user actually modifies a preference, so the date
command being run (which is supposed to check the last-modified state of the PLIST) is erroring out because it isn't finding the preferences file.
This should be easy enough to fix. I just need to test the file exists and/or create it automatically as part of the initial setup.
The other issue you cited is driving me nuts. On my Mac, if you preview a conversation using SHIFT, and then press Escape instead of SHIFT to dismiss, the whole thing locks-up for at least fifteen seconds. I don't know if this is Alfred or QuickLook causing a problem, but I'm open to suggestions.
I'm considering previewing conversations through a WKWebView component that gets drawn using JXA's Objective-C bridge, but I'm also working on turning this workflow into a standalone app, because there are a lot more things I want to add to it. Between now and then though, I'll play with different options.
I can definitely add that feature. Additionally, I'll include an exposure in the preferences pane so that you can specify the output format (e.g. %timestamp% %sender% : %content%
). Good idea!
The first issue has now been patched. I'll start on your request tomorrow morning while I wait for my car to finish getting repaired.
In regards to the preferences file that makes sense, however are you sure it's actually being pulled each time the script runs, if that's how the PLIST is polled. I checked the PLIST file via cli and seems to be getting updated, but I run the script it seems to be stuck on full for some reason. It was funny because last night when I got it to work and I could have sworn I saw timestamps and then all the sudden they were gone.
I don't seem to be having that same preview lock-up issue. If I press SHIFT I can pre-view the message and then press ESC or SHIFT to dismiss the preview. Both seem to exit just fine without any lag or hanging.
Excited to hear what changes you have in store.
I knew something was missing. I just noticed that the chat preview icons are missing. btw, love the updated look. In the new v2.0 splash page here on github you show blue and green bubbles but on mine I don't see those since the v2.0 update.
I was confident it was being polled persistently, but I can definitely take another look!
The bubble icons should have been included in the workflow bundle — blue being for iMessage and green for SMS. That's very strange they're not showing-up. If you click on the "go to workflow install directory" option in the workflow editor, do you see the png
files in there?
@stephancasas Regarding the bubbles not appearing, I suspect @ke6yjc is either not syncing Alfred Preferences or the path they’re syncing to has spaces in the name. Your method of gathering the path seems to be adding a \
to escape the space, which is then interpreted literally.
The good news is that it’s trivial to fix and you’ll just remove code. In short, you don’t need INSTALL_DIR
at all because Alfred workflows run from their own directory. Instead of:
icon: {
path: `${INSTALL_DIR}/${icon}.png`,
},
You can:
icon: {
path: `${icon}.png`,
},
And it will then work.
It'll be a good opportunity to repackage/re-factor for Alfred Gallery, too.
I was visiting the repo specifically with that in mind! We can move the conversation to another issue if you prefer, but the workflow seems pretty much good to go for the Gallery, except:
Howdy, @vitorgalvao!
That's good to know about the execution context. I had no idea that this was the case. Tomorrow afternoon I'll get this updated!
Thank you for the pointers on getting the workflow prepared for Gallery. After applying tomorrow's fix, I'll remove the updater and provide you with the specified screenshots.
The theme is a modified version of a Big Sur theme I found some years ago. I'll include it in the attachments of this comment!
I was confident it was being polled persistently, but I can definitely take another look!
The bubble icons should have been included in the workflow bundle — blue being for iMessage and green for SMS. That's very strange they're not showing-up. If you click on the "go to workflow install directory" option in the workflow editor, do you see the
png
files in there?
Yes the images in there and I think @vitorgalvao found the issue. However, it's been working sporadically and I keep getting this error. Do you want me to move this to another issue or just keep it going here?
[04:36:43.410] Mouseless Messenger[Script Filter] Queuing argument '(null)'
[04:36:43.733] Mouseless Messenger[Script Filter] Script with argv '(null)' finished
[04:36:43.737] ERROR: Mouseless Messenger[Script Filter] Code 1: /Users/demouser/Library/Caches/com.runningwithcrayons.Alfred/Workflow Scripts/66759147-8503-47A8-9DD9-21F493AF0918: execution error: Error: TypeError: undefined is not a function (near '...ObjectAndReturnError(0).string;...') (-2700)
@ke6yjc Just now, I am seeing this issue as well.
Since it's directly related to de-serialization of the message body, let's keep it in this issue.
@ke6yjc, from my end, it looks like this problem may be caused by messages which are "unsent." The sqlite database sets the attributedBody
column to null
for those rows in the message table which represent unsent entries.
In your recent conversations, do you see an indication that someone unsent a message too?
Yes, I had to unsend a few message the other day.
Just a heads up that I haven't forgotten this. I'm trying to roll-in a patch for iCloud Messages, too.
Sounds good! Let's hope that 13.2.1 didn't break something else! LOL
I'm experiencing the same issue, dropping my error message in case it is helpful.
As a note I have not unsent anything recently, and I do not know if anything sent to me has been unsent.
[18:44:00.030] Mouseless Messenger[Script Filter] Queuing argument '(null)'
[18:44:00.487] Mouseless Messenger[Script Filter] Script with argv '(null)' finished
[18:44:00.492] ERROR: Mouseless Messenger[Script Filter] Code 1: /Users/user/Library/Caches/com.runningwithcrayons.Alfred/Workflow Scripts/8A63AC6C-0D80-4B64-8BDE-0185E08A5113: execution error: Error: TypeError: undefined is not a function (near '...ObjectAndReturnError(0).string;...') (-2700)
Workflow Vesion: 2.0
Computer: Macbook Air M2, 2022
OS: Ventura 13.3
Hi, all.
This issue should be addressed in v2.0.1.
The auto-updater should kick-in but, if it doesn't, please feel free to grab it here.
@stephancasas With the bug fixed, and I see you have also commented out the update function, this is almost ready to go in the Gallery. Two small things remain:
@vitorgalvao Shoot. I forgot about that.
Thanks for the heads-up, and I'll get this done this tonight. 🎉
@stephancasas Checking up on the progress here. The Gallery page has been ready for quite a while but it still needs the small quick fix from above and the screenshot.
@vitorgalvao Howdy, and thanks for checking-in!
I've just pushed the icon-related change and included default-workflow.png as a screenshot for the gallery.
My apologies for the delay on this. I was wanting to get #8 fixed-up before going to Gallery, but it does seem to be affecting a limited number of users, and I can look further into it as additional feedback emerges.
Thank you for your help and your patience!
Thank you @stephancasas. But that change also reenabled the auto-update check, which needs to be disabled.
@vitorgalvao That's bizarre. I do not remember un-commenting that. This latest push has removed the functions entirely.
Thank you!
Outstanding. Thank you so much for your patience and help with this! 🥳
I'm noticing that messages I'm sending are not showing up is there a trick to getting them to show up. I need both sides of the conversation (with time stamps if possible) to forward into a CRM entry so I can document a conversation. Thanks in advance for the help!
Full Disk Access is enabled ✔️ Messages are being synced via iCloud ✔️ OS Ventura 13.2 Alfred 5.0.6