Jump to content

CJK

Member
  • Posts

    79
  • Joined

  • Last visited

  • Days Won

    7

Reputation Activity

  1. Like
    CJK got a reaction from gr8 in Can Alfred search the Mac Keychain   
    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"
  2. Like
    CJK got a reaction from aleone89 in Mapping arguments in Workflows   
    I went ahead and created the workflow for you using dummy data.
    You can download it here.
     
    As per your description, it's triggered using the keyword `wcp`, which accepts a single argument, currently `product1`, `product2`, ... , `product55`.  Upon selection, the URL referenced by argument entered gets passed to the next action.  There's an Open URL action waiting on the workflow's workspace, not yet connected to the trigger.  Instead, a Large Type output receives the URL, allowing you to preview the URL fully for testing purposes.
     

  3. Like
    CJK got a reaction from manavortex in Edit clipboard before pasting   
    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. Thanks
    CJK got a reaction from jmm28260 in Workflow to identify language in pdf   
    Would you mind doing me a favour and just sending me the PDFs that you are using for testing purposes ?  That way, I can see what sorts of content you're dealing with.
     
    This latest error, whilst very similar in nature to the one affecting the Title of the PDF document, seems odd that it would arise when dealing with a page from the PDF.  It implies that there was no language detected, which in turn implies the page had no text.  I can perhaps believe this might be the case for one random PDF file, but if you're presumably testing different files, then the others ought to work.
  5. Thanks
    CJK reacted to Andrew in [Solved] Output of Run Script (osascript) action terminates with line break   
    I just thought... it's worth adding that you do actually see the appended newline from osascript -e 'return "~/Downloads"' in Terminal. When using bash and echo -n, the next command is immediately after your output.
     
    Cheers,
    Andrew
  6. Like
    CJK got a reaction from jmm28260 in Workflow to identify language in pdf   
    Well, that took much more than just a minute.  Partly because your workflow was just kinda ugh, and partly because Objective-C is really bloody annoying on occasion, and the AppleScript needed to be re-written to cope with multiple file inputs, and because Automator can't do repeat loops by itself.

    Here's a screenshot of the Automator workflow, which now only has four actions:
     
    The modified AppleScript for use in the Run AppleScript action is below.  Largely, the screenshot and script are for the benefit of anyone viewing this post at a later date, from which they can piece together the workflow themselves because I still haven't set up a base for storing permanent links to fileshares, so this one will be temporary:
     
    Append Language To Name of PDF File.workflow.zip
    use framework "Foundation" property this : a reference to current application property NSFileManager : a reference to NSFileManager of this property NSLinguisticTagger : a reference to NSLinguisticTagger of this property NSString : a reference to NSString of this property nil : a reference to missing value on run [fs, null] script fileURLs property list : fs end script set FileManager to NSFileManager's defaultManager() repeat with f in the list of fileURLs try set lang to "_" & ((NSLinguisticTagger's ¬ dominantLanguageForString:(NSString's ¬ stringWithContentsOfURL:f)) as text) set basename to (NSString's stringWithString:(f's ¬ POSIX path))'s stringByDeletingPathExtension() set oldname to (basename's ¬ stringByAppendingPathExtension:"pdf") set newname to ((basename's ¬ stringByAppendingString:lang)'s ¬ stringByAppendingPathExtension:"pdf") tell the FileManager to moveItemAtPath:oldname ¬ toPath:newname |error|:nil -- Rename PDF file tell the FileManager to trashItemAtURL:f ¬ resultingItemURL:nil |error|:nil -- Delete text file end try end repeat end run
  7. Haha
    CJK reacted to deanishe in Workflow to identify language in pdf   
    Yeah, it's a bit of a mess. You keep setting Titre to various filepaths, not the PDF's title and you're using CJK's AppleScript incorrectly. You can't just copy-and-paste it (the variable input_string doesn't exist). You have to read the contents of the text file you create and pass that to the script.

    I tried to fix it myself, but I couldn't because I'm only able to use programming languages that aren't completely stupid while this requires AppleScript. Perhaps CJK can fix it.
     
  8. Like
    CJK got a reaction from deanishe in Workflow to identify language in pdf   
    Please don't nest tell application blocks inside each other when you don't need to (which is basically ever).  It's bad in many ways.  You should group things together so that the stuff FineReader does goes only inside a tell app "FineReader" block.  The System Events stuff goes separately inside its own block, etc.

    Anyway, you might not need to use that script.  You said you were doing this in Automator.  Automator has an action specifically for extracting text from a PDF file:
     

     
    Once you have plain text, detecting the language with AppleSript is pretty easy.  Say you store your string in an AppleScript variable called input_string, then the following code will return the language code for what it believes to be the most likely, dominant language that makes up the string (e.g. "en" for English, "de" for German, etc.):
     

    use framework "Foundation"
     
    property this : a reference to current application
    property NSLinguisiticTagger : a reference to NSLinguisiticTagger of this
     
    NSLinguisticTagger's dominantLanguageForString:input_string
    result as text

  9. Like
    CJK got a reaction from rodrigobdz in Workflow: Chrome Incognito - Open Google Chrome in Incognito mode.   
    Let me save everyone a 97MB slow download of a 1-minute video that could easily have been a 3-second GIF, that could easily have just been some words: when launching Chrome in incognito mode via the workflow being discussed in this thread, it does, indeed, open an incognito Chrome window, but also appears to open a normal Chrome window behind it.
  10. Thanks
    CJK got a reaction from Bhishan in [SOLVED] Problem with copying screenshot to current directory   
    Sorry, I see now that your original script returns the basename.  I mistook it originally for returning the full path, so engineered my version of the script to do the same.  It's one small modification in the way I declared the variable fp, and concatenated it with $name from the outset.  Instead, we'll just keep them as two separate variables, so $fp will contain the file path to the containing folder, and $name will contain the basename that you're after:
    fp=$(osascript -e \ "tell app \"Finder\" to get insertion location as alias return the result's POSIX path") screencapture -i -x "$fp$name.png" # copy final path to clipboard printf '%s' "$name.png" | pbcopy  
     
  11. Thanks
    CJK got a reaction from Bhishan in [SOLVED] Problem with copying screenshot to current directory   
    Having had a brief look at the workflow and the bash scripts, my guess is that when you substitute in "Google Drive", you're not using quotes to enclose the full file path, e.g. where you have, in one script:
    /bin/mv $a ${HOME}/Dropbox/KeepMe/KeepScreenshot/${name}.png would be better if it were:
    /bin/mv "$a" "${HOME}/Dropbox/KeepMe/KeepScreenshot/${name}.png"  
    My other suggestion, though unrelated to your present dilemma, is that you combine your four Run Script actions into a single action.  It doesn't make much sense to have them separate, and it'll make debugging easier too.
  12. Thanks
    CJK got a reaction from Bhishan 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  
  13. Like
    CJK 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:
  14. Like
    CJK reacted to bikeNik in Alfred-Icons [thenounproject.com]   
    This service has another public endpoint of their API - without registration and limitation to 5,000 requests. And its allows downloading the SVG file via my another version workflow simple by click on the one of the search result. But I'm not sure about legality to publishing it. I'm just leaving a link for this alternative version.
  15. Thanks
    CJK reacted to dfay in Snippets to work only with certain Lauguage input   
    You'd need to call up Alfred then type the keyword.  A snippet trigger aves a keystroke but more importantly it's less of an intrusion into ordinary typing flow (in my experience).
  16. Like
    CJK reacted to Korean Guy in Snippets to work only with certain Lauguage input   
    I love the snippets feature and uses like 100 times a day!
    One thing I wish Alfred could is, I could set up a certain group of snippets to be working on certain language input mode only
    for example I use ;br to make it best regards, I never type ;br on English, but I use it when I type different language.
    So it would be nice to make it disable this snippet to work when I'm using different language.
    Many thanks!!!!
  17. Like
    CJK reacted to deanishe in APIs for remotely executing Workflows   
    I don't think that's realistic, as it's a fundamentally cloud-based API (as best as I can tell). It's really designed to work with other Internet-based services, not ones local to your LAN. ssh would be a terrible choice of protocol for connecting from a server to your local machine (rather than vice versa) because it's far too powerful to make it secure. You'd want to use HTTPS instead.

    Either you'd need dynamic DNS set up, plus a hole in your firewall, so the Alexa/Amazon server can connect to an HTTP server on your Mac, or you'd use some client process on your Mac long-polling the Amazon server for pending messages.
     
  18. Like
    CJK reacted to irish.cn in APIs for remotely executing Workflows   
    I would love to see APIs to be able to remotely execute Alfred Workflows.
     
    I was just thinking of all the ways I'd like to be able to control my Mac with Alexa. Most of which, if not all, I could accomplish if I could just have Alexa execute specific workflows in Alfred. I know the fear might be that exposing such APIs would lead to Alfred Remote competitors. However, I believe you could handle that with licensing or even make APIs a paid feature of Alfred. 
     
    Just a thought, would love to hear other people's thoughts/input. Anyone else considered Alexa/Alfred integration?
     
    Thanks,
    Chris
  19. Like
    CJK reacted to Vero in Edit clipboard before pasting   
    @manavortex @Ovi What kind of modification do you have in mind when wanting to change text in the item you've copied to clipboard?
     
    To be clear, we have no intention of adding a text editor to Alfred to edit arbitrary text before pasting, but there may be some clever ways you can do what you want with a workflow or snippet.
     
    For example, if you have text that you want to paste with a few repeated changes every time (e.g. change someone's name, the price of something, etc), that could be achieved using a dynamic placeholder in a snippet. It's a much more efficient way and predictable way to paste something with specific elements changed every time.
     
    If that's what you have in mind, take a look at the built-in workflow Getting Started > Snippet Triggers to see them in action. You'll also find a tutorial on using Snippet Triggers with dynamic content here:
    https://www.alfredapp.com/help/workflows/triggers/snippet/snippet-triggers-with-dynamic-inputs/
     
    If you have something else in mind, do share, as there may very well be ways to do it already
     
    Cheers,
    Vero
     
     
  20. Haha
    CJK reacted to deanishe in Script Filter variables not passed down   
    Which bit isn't working? How do I get the problem to occur?
     
     
    Could be Invision Power Board's slogan, tbh.
  21. Like
    CJK reacted to rice.shawn in Workflow development   
    You've always been pretty good about keeping things organized from the get-go, which is, really, the best practice that anyone could have.
     
    While it is fun to build convoluted scripts for problems that exist either barely or theoretically (or is that just me?), it is probably a better use of your time to work on something more substantial than the build scripts.
     
    ---
     
    As for me, I'm not a Python guy, and my organization isn't nearly as good as Dean's. But, here's what I'd do if I had a standard way of doing things:
     
    Each of my workflows would have two main directories:
    1. lib
    2. scripts
     
    And each would (usually) have two scripts in the root:
    1. filter.{EXT}
    2. action.{EXT}
     
    `filter` is just whatever script filter it is in, and the `action` should probably be called router because it actually just parses the action query and calls the right script (in the scripts directory) from there. All library files go in `lib`.
     
    That works well enough for workflows written in Php, Bash, and Ruby.
     
    Ideally, I'd keep all the code in a separate folder and use some symlinks like Dean does, but I'm not well-organized to do that. It'd also help me keep all the ST3 projects laid out well.
     
    Damn. What this thread says is that I need to re-organize my computer (take the "re-" off that).
  22. Like
    CJK reacted to deanishe in Workflow development   
    I start off with a project directory in ~/Code (where I keep my, well, code), usually named alfred-<worklflowname>.
     
    This directory is a git repo, which will probably go on GitHub.
     
    The actual source code goes in a src subdirectory. That way I can keep things that don't belong in the distributed workflow in the project (README.md, the compiled .alfredworkflow file, helper scripts or source graphics).
     
    I create an empty workflow in Alfred and add the icon. Then I copy the contents of it over to the src subdirectory I made. Then I delete the workflow in Alfred.
     
    I have two scripts to help with writing workflows. workflow-build.py creates the .alfredworkflow file from the specified directory. It's aimed at Python workflows and ignores .pyc files. workflow-install.py installs the workflow to Alfred's workflow directory (using the bundle ID as its name). Most importantly workflow-install.py -s symlinks the source directory instead of copying it, so I can keep the source code with my other code, not in Alfred's settings dir.
     
    I also write workflows in Sublime Text 3 (usually). I run them in iTerm, though, not in ST's terminal. I find ST's terminal isn't very reliable and chokes on a lot of output. It's also not great when the script needs arguments, which is often.
     
    The downside of using iTerm is that it uses my shell environment, not Alfred's, but I'm careful about keeping my system Python fairly pristine.
     
    I generally try to write workflow scripts as command-line apps, i.e. one main script that takes options and arguments, rather than a bunch of separate scripts. I find this helps me design the app in a more sensible way. If the workflow needs a whole bunch of action scripts, I also prefer to keep these all in the same script and Run Script action (I add the options to {query}). That way I don't have dozens of elements in Alfred's UI, which is a PITA to manage.
     
    The thing to watch out for when doing this is your imports. If everything is in one script, you'll likely end up importing a bunch of libraries that won't be needed, which slows the script down. If I'm using libraries that are slow to import (OS X-native ones, like Foundation or AddressBook are the worst), I import them in functions that use them, not at the top of the script.
     
    With something as big as ZotQuery, I'd still go with one main script and one main application class, but add sub-applications behind keywords, much like git or pip works.
  23. Like
    CJK reacted to olivierlefloch in Allow pasting from Alfred Clipboard into Alfred Prompt   
    I'd love to be able touse the Alfred Clipboard History when typing into the Alfred Prompt.
     
    Oftentimes I want to paste a value I copied a couple of "copy"-actions ago, instead of the latest one, into the Alfred prompt.
     
    Here's a typical use case:
     
      - I copy text I want to search for using a custom web search (say, a jira issue key)
      - I do some other work, copy a piece of code, etc.
      - then I want to use my Jira custom Web Search
      - I open the Alfred Prompt
      - I type in my custom web search prefix ("jira ")
      - I open the Alfred Clipboard History, and trigger the proper history entry for my jira issue key
      - Instead of going back to the Alfred Prompt, with my jira issue key completed, my Jira issue key gets pasted in the frontmost app
  24. Thanks
    CJK got a reaction from gingerbeardman in Can Alfred search the Mac Keychain   
    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"
  25. Thanks
    CJK got a reaction from Bhishan 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.
×
×
  • Create New...