I’ve tried as many combinations as I could piece together from other posts but haven’t had an luck.
I want to set up an action that will search the whole currently open draft and find the timestamps at the beginning of each line and delete it (or replace with nothing).
The timestamps are all the same format but each line is different numbers depending on the time:
2023-08-21 07:45:00.123456+1000
I added a new action with 1 step ‘Script’ in various ways using:
%Y-%m-%d %H:%M:%S.%6%z
strftime is a tool to convert a date object into a string. It, unfortunately, does not do anything related to finding existing date strings.
Could you share some example lines from the data you are working with? It might be easier to suggest solutions. For example, if there is always a separator character, and the dates are always at the beginning of the line, it might be easiest to split the lines and remove the text. If not, regular expressions are probably needed and could be used either via find and replace or in a scripted action.
If I use regular expressions in the advanced find and replace do I just need the ^\d (etc) part? I tried a few date variations from the link to NSRegularExpressions to build a search string but no luck.
Sorry to be a pain, trying to get my head around it. My iOS has its heart hacked out so it could just be the ninjas have disabled actions, as it appears my Drafts app is a beta version - so they may have mucked around with the underlying ActionKit, EditorKit, StyledUI, DraftsUI or OperationKit.
Can you share a few lines in a code block (between triple backticks on this forum) I can paste into a draft and test with. It looks like a full pattern match that should work from what you shared.
Can you explain what you mean by this? I am running the Drafts beta, but I don’t fully understand what you are saying about the OS.
It is possible that the OP tried running your regex in the Find and Replace dialog - where I don’t think he needs the leading / or the ending /gm that are needed in the action script you provided.
I wouldn’t expect that to have given the result described, though I must admit by ‘running the code’, I was assuming that was running the action and not any other use of the information posted.
By beta I mean:
(//edited the links to the screenshots out as I thought github strips the binary the ratninjas have injected into every file I create but it shows up as being binary, sorry!)
I’m a captive of Stealth Developer Mode . I know the real Drafts code signing trust level isn’t 0
@Bjb I first tried it in actions (in 1 step). I also tried variations in the search and replace with regularexpression selected from the drop down.
I didn’t download the action as it had other code added in the ‘allow link to switch apps’ preview screen and I wasn’t sure if that was normally on them when they’re created or the added it as part of their app modification (stuff about groupDisposition, discoverabilityTitle, there was a groupUUID and another UUID). So I just copied the snippets in.
I’d be super grateful for any advice, tips, links on how to achieve it (if it is even possible to do).
I tried the regular expression and the action in Drafts (beta version of Drafts), and it gave the results below, which look correct to me.
Expand for results
0x36e1 Default 0x0 495 7 triald: (TrialServer) [com.apple.triald:server] Found 0 blocked tasks: (
)
0x36e1 Default 0x0 495 7 triald: (TrialServer) [com.apple.triald:server] Enqueueing eligible task <TRIFetchMultipleExperimentNotificationsTask:(null)> [tid:881]
0x36e1 Default 0x0 495 7 triald: (TrialServer) [com.apple.triald:server] enqueued follow-up task <TRIFetchMultipleExperimentNotificationsTask:(null)> [tid:881] after execution of [tid:879]
0x36e1 Default 0x0 495 7 triald: (TrialServer) [com.apple.triald:server] adding task to task queue: <private>
0x36e1 Default 0x0 495 7 triald: (TrialServer) [com.apple.triald:server] adding task with 0 dependencies to task queue: <private>
0x36e1 Default 0x0 495 7 triald: (TrialServer) [com.apple.triald:server] Found 3 dependency-free tasks to consider starting for capability 26: <private>
0x36e1 Default 0x0 495 7 triald: (TrialServer) [com.apple.triald:server] Partitioning task group into runnable/blocked for capabilities 26
0x36e1 Default 0x0 495 7 triald: (TrialServer) [com.apple.triald:server] Found 3 runnable tasks: (
"[tid:882]",
"[tid:880]",
"[tid:881]"
)
0x36e1 Default 0x0 495 7 triald: (TrialServer) [com.apple.triald:server] Found 0 blocked tasks: (
)
0x36e1 Default 0x0 495 7 triald: (TrialServer) [com.apple.triald:server] Enqueueing eligible task <TRISelectRolloutNotificationListTask:(null)> [tid:882]
0x36e1 Default 0x0 495 7 triald: (TrialServer) [com.apple.triald:server] enqueued follow-up task <TRISelectRolloutNotificationListTask:(null)> [tid:882] after execution of [tid:879]
0x36e1 Default 0x0 495 7 triald: (TrialServer) [com.apple.triald:server] Found 3 dependency-free tasks to consider starting for capability 26: <private>
0x36e1 Default 0x0 495 7 triald: (TrialServer) [com.apple.triald:server] Partitioning task group into runnable/blocked for capabilities 26
0x36e1 Default 0x0 495 7 triald: (TrialServer) [com.apple.triald:server] Found 3 runnable tasks: (
"[tid:882]",
"[tid:880]",
"[tid:881]"
)
0x36e1 Default 0x0 495 7 triald: (TrialServer) [com.apple.triald:server] Found 0 blocked tasks: (
)
0x36e1 Default 0x0 495 7 triald: (TrialServer) [com.apple.triald:server] Starting <TRIRetargetAllTask:0x******b80> [tid:880] with tags {}
0x36e1 Default 0x0 495 7 triald: (TrialServer) [com.apple.triald:server] Using persisted experiment opt-out: '0'
0x36e1 Info 0x0 495 0 triald: (Trial) [com.apple.trial:_] Logging log event: <private>
0x36e1 Default 0x0 495 7 triald: (TrialServer) [com.apple.triald:server] <TRIRetargetAllTask:0x******b80> [tid:880] finished with status COMPLETED
Looking at your notes on GitHub, “Stealthy Developer Mode” is a hack of app betas. I’m pretty sure that puts you in the camp of firmly unsupported use.
Okay, so I think you are pretty safe from “rat ninja” (BTW plurals for Japanese words like ninja would generally not have an “s”) - the only one I’ve come across is from TMNT and I’m pretty sure he’s not on this forum
The details you are describing are part of the action - you would be able to note this by exporting and URL decoding your own actions in Drafts. Many objects in computing get a UUID to ensure uniqueness.
My advice is…
Use the App Store version of Drafts - don’t use exploits.
Use the action that has been shared with you - I’m pretty sure it does what you asked for.
Confirm the regex works using a regex tool and your sample data - regex101 is a good one.
I did download Drafts from the AppStore, I also have the subscription version through Apple. I haven’t ever had any involvement with beta anything but theres still an active exploit allowing whoever they are to do what they do - because nothing we do will get rid of it. Aside from paying a ton of $ for a cyber security expert, we’re stuck waiting for a researcher to take up the challenge and find the hole to plug.
*grin about the ninja plural, maybe I should rename them the MacGyverRats since everything is a mashup of versions of every OS ever created!
if this is a one-time issue (clean this file with this date mess starting each line), a simple way is straight JavaScript testing of each line. Split text into an array of lines, then:
for ( t of lineArr) { // gets each line into t
if (new Date(t.substr(0,32)!=“Invalid Date”) { t = t.substr(33);}
// new Date(t) makes a Date object from the t.substr(0,32) but is ‘Invalid Date’ for strings
}
then rebuild your draft.
that should do it (the values of 32 & 33 may not be right). I checked the entire line (timestamp + extra string), and a (" " + timestamp); they will generate a Date object, but an ‘Invalid Date’; I also checked (0x36e1) and also invalid.
Can you provide an example set of content to demonstrate the undesired behaviour?
All I can think is that it will currently match longer Hex strings being expressed in the same notation. If there were always a space after then that could be used in the original replace within the match and the substitution parameters. If it varied, then perhaps using a word boundary token would allow the required flexibility?
This line is a good example, one is 0x143e1fb80 {9} another is 0xbd5e1be7791c20c8 {16}.
I’ve been learning new ways to use the advanced find and replace a fair bit but it uses a different regex flavor (swift?) to the actions regex which is javascript? I know with the advanced option I can specify the end with \b, so if it doesn’t match it ignores it. I’m still trying to master actions because they’re much quicker unless there is a way to save advanced search & replace?
The majority always have a space after it but can sometimes have “ or / or > at the end.
Not commenting on the regex code, but just in terms of the Javascript, you might need to clarify some basics of replace functions.
If you only want to replace the first occurrence of something, you can use replace, instead of replaceAll.
The error you are likely getting with the match code you posted is that the regex is not closed (no end / before the parenthesis), but also that’s not value code for replacement. Here’s a few examples, just using a placeholder regular expression:
// replace only first match
draft.content = draft.content.replace(/REGEX/, "REPLACEMENT")
// replace all occurrences of matches
// note the `g` global flag on the regex
draft.content = draft.content.replace(/REGEX/g, "REPLACEMENT")