Jump to content


  • Content Count

  • Joined

  • Last visited

  • Days Won


Everything posted by CJK

  1. I have noticed that there's a Snippet Trigger, which I assume allows one to create a keyword shortcut that acts as a snippet, expanding to whatever result of the ensuing workflow yields. Is that anywhere close to how it works ? If so, an off-the-top-of-my-head idea and without much firsthand experience using Alfred snippets (I use Typinator), makes it seem to me that it might be possible to create snippets that share a common abbreviation/keyword, but—through a multi-pronged workflow that incorporates a tiny bit of scripting—could expand to produce something that depends entirely upon the currently selected keyboard input source. I'm not the best person to play around with this, as I'm monolingual. However, I have put together a few lines of key Javascript for Automation (JXA) code that would prove useful if anyone else wanted to see what they can do to make snippets more flexible or less likely to clash for multilingual persons: ObjC.import('AppKit'); inputContext = $.NSTextInputContext.currentInputContext; inputSources = ObjC.deepUnwrap(inputContext.keyboardInputSources); inputSource = ObjC.unwrap(inputContext.selectedKeyboardInputSource); //--> "com.apple.keylayout.British" localisedName = ObjC.unwrap( $.NSTextInputContext .localizedNameForInputSource(inputSource) ); //--> "British" I've printed example values for the last two variables, which are actual values returned on my system. The other value of possible interest is the variable inputSources, which produces a list of available input sources, mirroring what appears listed in the input menu if you have it accessible from the menu bar.
  2. I think this a good suggestion that would push Alfred progressively forward in line with competitors of similar ilk. Can Alexa execute commands via SSH ? In the interim, you could possibly achieve a similar result if you were able to get Alexa to run an osascript command over SSH into your machine.
  3. Not a complete solution, but this establishes a hotkey that takes highlighted text in Safari, runs it through your regex, then sends the result to the clipboard. Here, I've elected to use 〈Ctrl〉+〈C〉 as a close relative of 〈Cmd〉+〈C〉.
  4.  Could be Invision Power Board's slogan, tb Megalolz.
  5. You could use the Transform utility to edit it.
  6. So your workflow is set up exactly the same as mine, and now using exactly the same script. Yet yours presents with a 5-second delay in _Alfred_, and mine does not. This might suggest that it's something specific to your system that is creating the delay. You could try debugging the workflow. Mine didn't reveal anything interesting, so if yours does, that might be a clue. Otherwise, see if anyone who knows more than I chimes in with some suggestions or ideas.
  7. Web form passwords aren't part of the accessible keychain, either through Usable Keychain Scripting or regular Keychain Access apple scripting, or even through bash security program. I believe those are stored in the iCloud keychain, and not the login keychain. Such a pain, but possibly good from a security standpoint.
  8. More AppleScripting terminology would facilitate this and allow implementing this feature through a workflow. For example, being able to reference the text currently input into the search bar.
  9. The AppleScript itself by Michael Kummer is a functionally-good script and undoubtedly extremely useful, but it's pretty terribly written and has a few inefficiencies in its code. I doubt it will account for 5 seconds, but I've refactored (of sorts) the code to make it more articulate and efficient, below. How have you implemented the above AppleScript into an Alfred workflow ? Do you have a screenshot of the workflow or the workflow itself ? When I implemented my version of the script, I did so in this fashion: and the script ran instantaneously. System info: AppleScript version: 2.7 System version: 10.13.6 Alfred version: 3.7 # Set this according to your email account names and Reminder's lists set WorkAccountName to "Exchange" set WorkRemindersList to "Work" set PersonalAccountName to "iCloud" set PersonalRemindersList to "Personal" # On my machine 5 is the Purple flag, which is the color I would like to use for mails flagged as Reminder set FlagIndex to 5 tell application "Mail" # do nothing if no email is selected in Mail set [theMessage] to the selection & {null} if theMessage = null then return set theSubject to theMessage's subject end tell # Make sure reminder doesn't already exist so we don't create duplicates tell application "Reminders" to set needle to a reference to ¬ (the last reminder whose name = theSubject and completed = false) if the needle exists then tell the button returned of (display dialog contents of [¬ "The selected email matches an existing reminder: ", ¬ needle's name, ". Would you like to mark the reminder as ", ¬ "complete and clear any remaining flags of this message?"] ¬ as text with title ["Create Reminder from E-Mail"] ¬ buttons ["Mark complete", "Cancel"] ¬ default button 1) to if it = "Cancel" then return # unflag email/message tell application "Mail" to set flag index of theMessage to -1 # find correct reminder based on subject and mark as complete tell application "Reminders" to set completed of the needle to true return end if # present user with a list of follow-up times (in minutes) set [reminderDate] to {} & (choose from list [¬ "Tomorrow", "2 Days", "End of Week", ¬ "1 Week", "1 Month", "3 Months"] ¬ default items ("End of Week") ¬ OK button name ("Create") ¬ with prompt ("Set follow-up time") ¬ with title ("Create Reminder from E-Mail")) # Exit if user clicks Cancel if reminderDate = false then return if reminderDate = "Tomorrow" then set remindMeDate to (current date) + 1 * days else if reminderDate = "2 Days" then set remindMeDate to (current date) + 2 * days else if reminderDate = "End of Week" then # end of week means Thursday in terms of reminders # set the reminder for Thursday, except: # if it's Thursday, set the reminder for Friday # if it's Friday, set the reminder for Thursday next week set curWeekDay to weekday of (current date) as integer set n to (12 - curWeekDay) mod 7 -- Number of days until Thursday if n = 0 then set n to 1 -- Thursday is the exception -> Friday set remindMeDate to (current date) + n * days else if reminderDate = "1 Week" then set remindMeDate to (current date) + 7 * days else if reminderDate = "1 Month" then set remindMeDate to (current date) tell remindMeDate to set its month to (its month as integer) + 1 else if reminderDate = "3 Months" then set remindMeDate to (current date) tell remindMeDate to set its month to (its month as integer) + 3 end if set time of remindMeDate to 9 * hours -- 9a.m. on day of reminding tell application "Mail" # Flag selected email/message in Mail set theMessage's flag index to FlagIndex # Get the unique identifier (ID) of selected email/message set theOrigMessageId to theMessage's message id end tell #we need to encode % with %25 because otherwise the URL will be screwed up in #Reminders and you won't be able to just click on it to open the linked message #in Mail set theUrl to the contents of ["message:%3C", ¬ replaceText(theOrigMessageId, "%", "%25"), ¬ "%3E"] as text # determine correct Reminder's list based on account of email/message tell application "Mail" to tell the account of theMessage's mailbox to ¬ if its name = WorkAccountName then set RemindersList to WorkRemindersList else if its name = PersonalAccountName then set RemindersList to PersonalRemindersList else #default list name in Reminders set RemindersList to "Reminders" end if # create new reminder with proper due date, subject name and the URL # linking to the email in Mail tell application "Reminders" to tell list RemindersList to ¬ make new reminder with properties {name:theSubject ¬ , remind me date:remindMeDate, body:theUrl} display notification "Reminder set" with title ¬ theSubject subtitle remindMeDate as text # string replace function # used to replace % with %25 on replaceText(subject, find, replace) set text item delimiters to {replace, find} subject's text items as text end replaceText This version of the script also leaves Reminders in the background, without bringing it into focus, as there's no need. This way, it doesn't pull your attention away from your emails when you're sifting through messages and triggering the script.
  10. Yes, I believe so. You can take the first workflow (`throw`) and append a _System Command_ action, for which you would choose "Empty Trash". Then prepend to all of this a hotkey that triggers this sequence of events. No AppleScript ought to be needed.
  11. Can you be more specific ? In what way doesn't it work ? Or, put another way, what precise result should you be getting, and what precise result are you getting now ? "Doesn't work" can range from the script failing to execute at all because of an error during compile time; or the script running but returning no result; or the script not recognising the command names; or a host of other possibilities. Perhaps you could upload one of your workflows where this problem can be seen first hand, and someone could help diagnose the cause for you ?
  12. Perhaps. But that's missing the point. It doesn't matter for now, if I can collect my thoughts on the matter, I'll put together a feature request post. Then again, I might not. I shouldn't think AppleScript will be prioritised anyway, given how painfully it's dying.
  13. I think you're going to need to resort to a GUI check, sadly. On this note, I really do think Alfred would benefit from more AppleScripting terminology, to include things such as whether the Alfred search bar is active or not, or to automate editing features of multiple workflows (a workflow object would be very useful).
  14. Yes, I've wanted to do this in the past, but ran into difficulty. Although there's the option to have a hotkey only active when a particular app has focus, this only means that the hotkey won't do anything outside of that app; it doesn't mean the hotkey is available to be used by other apps to trigger their workflows. This is really irksome, because it severely limits the amount of hotkey "real estate" one has to play with—double tapping the Command key is such a useful trigger, but with Alfred, I can only get it to serve a single purpose (thankfully, I have Keyboard Maestro installed, so I use that to apply multiple actions to a single keyboard trigger depending on different factors).
  15. Yes, e.g.: var app = Application('Usable Keychain Scripting') app.currentKeychain.keychainItems.whose({name: {_contains: 'CK'} })() I don't have Mojave but I'm hearing lots and lots of reports that it's ballsed everything up for AppleScripters, particularly as it no longer permits the use of scripting additions (people wonder why I never use them, and this is why). However, as the Usable Keychain Scripting is an application, it can be scripted just like any other scriptable application that one downloads.
  16. Hi @Bhishan, Here's the equivalent code for Chrome that closes all windows and all tabs except the currently active one: use Chrome : application "Google Chrome" property |windows| : a reference to every window of Chrome property |tabs| : a reference to every tab of |windows| property tab : a reference to the active tab of Chrome's front window close (|tabs| where its id ≠ id of my tab) It's very similar to the Safari code, but Chrome requires that comparing tabs is done via their id property rather than directly as object references.
  17. I wish you had asked this in your initial question. It's extra work to go back and test a script in different situations after the fact, rather than had I known and been able to do the testing all at once. I'm too tired to go and test anything for Chrome, but it would involve changing current tab to active tab, and utilising the id property of my tab to exclude it from the enumerated list of id of |tabs|. Play around with it and just do trial-by-error. That's what we all do. Regarding Firefox, it won't work. Firefox isn't scriptable (to any useful extent). I'll check back in a couple of days and post a working solution for Chrome if you haven't got it figured out by then. Next time, please include all your related needs in a single post. Obviously, very disparate issues are still best posted as separate posts.
  18. AppleScript's "KeyChain Access" is pretty terrible. However, the kind bloke(s) at Red-Sweater software (maker of FastScripts) have made a scripting addition aptly referred to as the Usable Keychain Scripting It allows you to search using whose filters as with other enumerated AppleScript collections, e.g. tell application "Usable Keychain Scripting" to tell ¬ the current keychain to get the ¬ password of every internet password ¬ whose name contains "google.com"
  19. You could try this: use Safari : application "Safari" property |windows| : a reference to every window of Safari property |tabs| : a reference to every tab of |windows| property tab : a reference to the current tab of Safari's front window close (|tabs| where it ≠ my tab) I haven't really tested it though as I currently have a gajillion tabs open that I don't particularly want to close. Also, don't use the Run NSAppleScript action. Use the Run Script action and select /usr/bin/osascript (AS) as the chosen language.
  20. @Bhishan, this is the general form the AppleScript code will take when trying to access a menu bar icon and its menu: use application "System Events" property P : a reference to the process named "Mathpix Snipping Tool" property M : a reference to menu bar item 1 of menu bar 2 of P property I : a reference to the menu item named "Get LaTeX" of menu 1 of M click M click I It doesn't work for every single menu bar application, and there's an annoying 5-second delay between the first click command and the second. This is a known, persistent feature that has various documented so-called solutions, none of which are reliable, but you can have a Google and see what works for you. Don't forget to make sure Terminal (or whichever program is executing the above script) has accessibility privileges granted to it.
  21. I was just brainstorming out loud. I wasn't suggesting that as an actual final solution. But when I mentioned a wrapper of some sort, I just remembered that there's a site called https://itty.bitty.site that does something along these lines. I actually used them for my homepage since I have no hosting space. Basically, it encodes and decodes a webpage up to the length of about 2000KB into a URL, which then circumvents the need to have small web pages hosted at all. But, anyway, this is a digression. I'll have a look at vitor's repo, cheers for the link... EDIT: ...which I've now done. It's a good interim solution for sure. I'll do that from now on. Thanks for pointing me there.
  22. Saw this remark from a while ago, and things may have changed. What method do you use to adjust this setting ?
  23. I'll endeavour to sort something out for future contributions, however all of my current cloud storage solutions are also set to sync with my local laptop hard drive. This means any workflow I share through these would need to remain there and also on my hard drive, as a duplicate of the one that already exists (the original). May I ask how you manage this situation for yourself ? The other issue with cloud storage solutions is that links can break easily simply by renaming or moving a file when one reorganises. So I imagine that's another issue for the Alfred forum even for seemingly "permanent" links. I wonder if there's a superior solution that bypasses the need for links and cloud storage. Perhaps along the lines of encoding the workflow file in base64 and pasting the output on the Alfred forum as text (but ideally with a more user-friendly wrapper for those who wouldn't feel able to decode base64, not to mention the absurd-looking forum posts we'd start seeing). I rrrrrrreally wish the Alfred forum was a Discourse forum.
  24. @MrAu, Here's my humble offering, which may be no better or no worse than any others. The workflow is downloadable here and will available for the next 30 days at which point the link expires. Here's a screenshot of the workflow: As you can see, it's very straightforward, so not much can go wrong.
  25. [background=#eee][font=courier,monospace]sample inline code typeface[/font][/background] should render as sample inline code typeface. This font is Menlo
  • Create New...