Jump to content

Bhishan

Member
  • Posts

    146
  • Joined

  • Last visited

Reputation Activity

  1. Thanks
    Bhishan reacted to CJK in [SOLVED] Problem with copying screenshot to current directory   
    In fact, this is your combined script just as a straight copy-n-paste (it obviously won't function yet because of the naked AppleScript code):
    screencapture -i -x ${HOME}/Dropbox/KeepMe/KeepScreenshot/$(date +%Y-%m-%d-%H-%M-%S).png # rename sleep 5 a=${HOME}/Dropbox/KeepMe/KeepScreenshot/*.png /bin/mv $a ${HOME}/Dropbox/KeepMe/KeepScreenshot/${name}.png tell application "Finder" if exists Finder window 1 then set currentDir to target of Finder window 1 as alias else set currentDir to desktop as alias end if end tell return POSIX path of currentDir # cd to cwd cd $1 # move png to cwd /bin/mv ${HOME}/Dropbox/KeepMe/KeepScreenshot/${name}.png ${name}.png # copy final path to clipboard pbcopy < ${name}.png There's a lot of renaming/moving and so forth going on, and I'm wondering whether it would have been easier just to set the destination path straight away when taking the screen capture.  That way, the entire script above gets reduced to this:
    fp=$(osascript -e \ "tell app \"Finder\" to get insertion location as alias return the result's POSIX path")$name.png screencapture -i -x "$fp" # copy final path to clipboard printf '%s' "$fp" | pbcopy  
  2. Like
    Bhishan reacted to Wangyou Zhang in Simplify fractions   
    I write a workflow for converting a given decimal to a simplified fraction as well as simplifying a given fraction.
    It saves me a lot of time and I hope it is useful for you too.
     
    Download
    You can download the workflow file from my GitHub.

    Examples

    frac .11 ==>  .11 = 11 / 100 frac 4/6 ==>  4/6 = 2 / 3 frac -1.4/2.2 ==>  -1.4/2.2 = -7 / 11 frac 1.2/0 ==>  Error: divided by zero. frac b/3 ==>  Error: Invalid input format  
    -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
     
    Update
    7 additional math tools are added and the new workflow is renamed to MathTools. 
    1) Simplify fractions
    Examples:

    frac .11 ==>  .11 = 11 / 100 frac 4/6 ==>  4/6 = 2 / 3 frac -1.4/2.2 ==>  -1.4/2.2 = -7 / 11 2) Greatest common divisor
    Examples:

    3) Least common multiple
    Examples:

    4) Simplify surds
    Examples:

    sqrt .0144 ==>  √(.0144) = 3/25 = 0.12 sqrt 4 8/81 ==>  ³√(8/81) = (2/3) ³√(1/3) Note:
    5) Log functions
    Examples:

    log 5 ==>  log₁₀(5) = 0.698970004336 log2 1.0001 ==>  log₂(1.0001) = 0.000144262291095 ln e ==>  ln(e) = 1.0 Note:
    6) Prime factorization
    Examples:

    factor 100 ==>  factor(100) = [1, 2, 2, 5, 5] factor 31 ==>  factor(31) = [1, 31] Note:
    7) Permutations and Combinations
    Examples:

    C( 4 2 ==>  C(4, 2) = 6  c( 1000 3 ==>  C(1000, 3) = 166167000  P( 4 2 ==>  P(4, 2) = 12 p( 1000 3 ==>  P(1000, 3) = 997002000  Note:
  3. Thanks
    Bhishan reacted to deanishe in [SOLVED] Write current Finder path to a text file   
    log POSIX path of currentDir sends the path to STDERR, i.e. Alfred's debugger, not to the next action.

    Use return POSIX path of currentDir to write the path to STDOUT instead, which will be sent to the next action.

    It isn't working in the shell, either. It just looks like it because both STDOUT and STDERR are written to the terminal. If you try to redirect the output to a file with > /path/to/file, you'll see it doesn't work.
  4. Like
    Bhishan reacted to aiyo in Send URL   
    I have finally converted my Send URL extension into a workflow.
     

     
    The workflow selects the URL from the frontmost App or a URL from the Clipboard. Supported Apps are:
    Safari Webkit Google Chrome (Beta/Dev/Canary) Camino Opera (and Opera Next) Omniweb  
    You can then send the URL to a variety of Apps
     
    Safari Webkit Google Chrome (Beta/Dev/Canary) Camino Opera (and Opera Next) Omniweb Firefox (and Aurora) iCab Sleipnir Paparazzi! Mail Sparrow Postbox Gmail VLC Adium (as a chat to an online contact) Droplr downforeveryoneorjustme.com and the clipboard  
    The workflow only list the Apps installed on you mac.
    You can download Send URL here:
    https://github.com/aiyodk/Alfred-Extensions/raw/master/AlfredApp_2.x/Send-URL/Send-URL.alfredworkflow
     
    EDIT:
     
    I have updated Send URL.  
    The update fixes a bug where the workflow would not work if the URL contains a '&' and downforeveryoneorjustme.com is not working correctly.
    I have also included options to copy the URL as a HTML or Markdown link (including the page title)
  5. Thanks
    Bhishan reacted to vitor in [SOLVED] How to Assign Keyboard Shortcut to empty Downloads and Trash Both?   
    @Bhishan You have way too much code. You can do it with
    tell application "Finder" delete every item of folder (path to downloads folder as text) empty trash end tell  
  6. Thanks
    Bhishan reacted to CJK in [SOLVED] How to Assign Keyboard Shortcut to empty Downloads and Trash Both?   
    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.
  7. Thanks
    Bhishan reacted to vitor in [SOLVED] Workflow to control Fenetre application   
    @Bhishan That’ll likely require scripting Fenêtre itself. You need to ask on their forums.
  8. Thanks
    Bhishan reacted to vitor in [SOLVED] Workflow to control Fenetre application   
    Press hotkey (set shortcut to only fire when Fenêtre does not have focus) → Launch Fenêtre (should bring it to the top) → Redo shortcut.
  9. Thanks
    Bhishan reacted to vitor in [SOLVED] Switch Between Multiple Terminal Windows   
    You can cycle through windows of the same app, on macOS. Or open new tabs and do the same.
  10. Thanks
    Bhishan reacted to deanishe in [SOLVED] Could not convert Fahrenheit to celcius in Script Filter   
    Uncheck "Alfred filters results".
     
    If that's checked, Alfred doesn't pass the query to your script.
  11. Thanks
    Bhishan reacted to vitor in [SOLVED] How to use "ESC" key in Alfred output key combo?   
    Why not? Doing it in a Key Combo works fine. It’s unlikely ⎋ (escape) will act as a modifier, so the shortcut is likely ⎋ m (one followed by the other rather than ⎋m (in tandem).
  12. Thanks
    Bhishan reacted to CJK in [SOLVED] How to close all Safari windows and tabs except current tab?   
    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.
  13. Like
    Bhishan reacted to CJK in [SOLVED] How to close all Safari windows and tabs except current tab?   
    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.
  14. Thanks
    Bhishan reacted to CJK in [SOLVED] How to close all Safari windows and tabs except current tab?   
    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.
  15. Thanks
    Bhishan reacted to CJK in How do I click a menu item of application in Mac menubar?   
    @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.
  16. Like
    Bhishan reacted to deanishe in How do I click a menu item of application in Mac menubar?   
    I've changed the title of your topic.
     
    [HOWTO] is for explanations of how to do something, not for questions.
     
  17. Like
    Bhishan reacted to advena in Problem with Write Text File using multiple variables   
    Hey @Bhishan--
     
    I decided to post this to the forum in case it helps someone else out.
     
    There were two main things I was doing wrong. First was running each variable on its own thread. For what I was doing, the proper thing to do was to have everything on one thread (and therefore running one after the other).
     
    The second issue I was having was with filters. You'll need to google to understand exactly why it happens (I don't understand it well enough to explain it), but I was having unwanted newlines & whitespace in the output. This meant filters weren't working as I expected (since the input to the filter had newlines etc I didn't know about). That was fixed by using some `Transform` and `Replace` utilities.
     
    I'll attach both of the workflows based around the original workflow.
     
    Hope these workflows help you figure it out
    -Scott
     
    Create a new note with or without selected text with Zettelkasten metadata
     
    Create a new note (with or without selected text) & PDF from Safari tab with Zettelkasten metadata

     
    Screenshots:
     
    New note:
     

     
    New note & PDF:
     

  18. Like
    Bhishan got a reaction from vitor in [SOLVED] Workflow to render GitHub ipynb files nicely using nbviewer.   
    @vitor   Apologies for forgetting to upload the  MWE workflow.
     
      For completeness,  uploaded posthumously:  workflow link
     
    Its sunday evening here in Ohio USA. I was not expecting answer until monday.  The Community of Alfred is awesome!
     
    I know there is one father and one mother of Alfred, I guess there are so many brother and sisters of Alfred who are helpful and active 
    almost all the time.
     
    Sorry for the probable XY question. Rather, I should have explained the problem and seek for the suggestions from the expert.
     
     
    Its always tempting to beliveve that if we know the small part, we can ourself solve the rest of the problem and avoid taking too much time of the helpers. But sometimes it goes the wrong way and instead the asker needs too much time of helper.
     
    Thanks again, the new workflow with JXA works nice and also helps to write further similar workflow.
    I need to look and grab some basic concepts of JXA now.
     
     
  19. Like
    Bhishan reacted to deanishe in Accessing workflow args in bash script   
    No, no, no. It's not my product, dude. Hell, all the worst (best, imo) rants on the forum against Alfred were written by me.
     
    I'm basically the resident dick on the forum. OTOH, for my occasional-to-frequent bad attitude, I'm also one of the most experienced workflow developers and often right…
     
    Sorry if you feel I went off in the deep end in reaction to your "Alfred's not like Linux: it's broken". That was a wee bit passive aggressive on your part, and tbh, passive isn't really my style. You should have seen the first draft of that post…
     
    Seriously, Alfred isn't bash. If you won't accept that, you're only causing difficulty for yourself ('cos it ain't gonna change).
     
    For what you want to do, you should do it the way I suggested. It works perfectly. Otherwise, you'll just be fighting with Alfred.
     
    To back up my claim of shitting on Alfred, the Script box is a terrible editor. No highlighting, no line numbers (which you need to track down inevitable errors), and embedding all your code in info.plist ruins source control.
     
    "What's changed? Info.plist!" Not super helpful…
     
    As a rule, it's a much better idea to put your code in a separate file, anyway (for the above reasons), and treat the Script box like a command line. 
     
    Put ./script.sh $1 (or ./script.sh "$1") in the Script box and the rest of your code in script.sh. It's the smart way to do it.
  20. Like
    Bhishan reacted to vitor in [SOLVED] How to write an Alfred workflow to "go to bottom of GitHub page and click Commit Changes" button ?   
    This is pretty easy to do with AlfredBookmarklet. The only code you need is document.getElementById('submit-file').click();. Here’s a ready-made version.
  21. Thanks
    Bhishan reacted to evanfuchs in [SOLVED] How to write an Alfred workflow to "go to bottom of GitHub page and click Commit Changes" button ?   
    I use a web-based software that is all button clicks with no keyboard shortcuts. Switching back and forth from mouse to keyboard drives me nuts. If the button is visible on the page, Keyboard Maestro's "Click at found image" is good for this sort of thing.
  22. Thanks
    Bhishan reacted to vitor in [SOLVED] How to write an Alfred workflow to "go to bottom of GitHub page and click Commit Changes" button ?   
    You’re going about this the wrong way. Don’t automate the page, use their API. If you understand bash, here’s a simple script that uses their API to merge PRs.
     
     
    This can’t be done with AppleScript. Automating the page requires you to inject JavaScript on the page to perform the actions.
     
    What exactly are you trying to do? Show us an example page and the exact action.
  23. Thanks
    Bhishan reacted to dfay in [SOLVED] How to write an Alfred workflow to "go to bottom of GitHub page and click Commit Changes" button ?   
    Fake.app is the easiest way to do stuff like this - but it may be overkill for your needs, if you don’t want to run the task in a separate browser.
  24. Like
    Bhishan got a reaction from deanishe in [SOLVED] Plot datafiles using Alfred and Python   
    @deanishe   Thanks for the suggestion, it worked now.
  25. Like
    Bhishan reacted to deanishe in Recommendations for Sharing Workflows   
    Not sure if this is quite the right thread, but if you're distributing a workflow written in Python, *do not* ask users to install Python libraries in the system Python. Bundle them with your workflow.
    It's not ideal, but installing libraries into the system Python is very bad form. The chances are good that you'll break some other software doing the same naughty thing—or it will break your workflow—by installing an incompatible version of a library.
    It's trivial to install libraries directly in your workflow with "pip install --target=my/workflow/dir". Do that instead.
    In addition, bundling the libraries with your workflow means the workflow will sync across machines without problems.
×
×
  • Create New...