Jump to content

deanishe

Member
  • Posts

    8,759
  • Joined

  • Last visited

  • Days Won

    522

Everything posted by deanishe

  1. I had a dig through some old, similar scripts and came up with this. It will work as a command-line script or pasted into the Script box of an Alfred Run Script action (set Language to Python). #!/usr/bin/env python # encoding: utf-8 # # Copyright (c) 2016 deanishe@deanishe.net # # MIT Licence. See http://opensource.org/licenses/MIT # # Created on 2016-01-11 # """ Copy files to OS X clipboard. Works as CLI script or Alfred File Action script. """ from __future__ import print_function, absolute_import import os import sys from AppKit import NSPasteboard from Foundation import NSURL def paths2urls(paths): """Convert `paths` into a list of NSURLs. Args: paths (list): Absolute filepaths. Returns: list: List of NSURL objects corresponding to `paths`. """ urls = [] for p in paths: p = unicode(p, 'utf-8') url = NSURL.fileURLWithPath_(p) urls.append(url) return urls def copy2pasteboard(items): """Place `items` on the general pasteboard. `items` *must* contain NSURLs. Args: items (list): List of NSURL objects. """ pb = NSPasteboard.generalPasteboard() pb.clearContents() pb.writeObjects_(items) def filepaths_from_argv(): """Read filepaths from command-line arguments. Returns: list: Absolute paths read from ARGV. """ return [os.path.abspath(p) for p in sys.argv[1:] if os.path.exists(p)] def filepaths_from_alfred(): """Return filepaths based on Alfred's { query } text macro. Parse Alfred's tab-separated list of paths. Returns: list: Absolute paths passed by Alfred. """ filepaths = "{query}".split('\t') filepaths = [f for f in filepaths if f.strip() and os.path.exists(f)] return filepaths def main(): """Run script.""" if os.getenv('alfred_version'): # Running in Alfred filepaths = filepaths_from_alfred() else: # Assume CLI filepaths = filepaths_from_argv() urls = paths2urls(filepaths) copy2pasteboard(urls) if __name__ == '__main__': main() Just attach this to a File Action (it works with multiple files).
  2. You can copy a file to the clipboard with AppleScript. This script will work on the command line and copy the first filepath passed to it to the clipboard: on run (argv) set the clipboard to POSIX file (POSIX path of ((POSIX file (first item of argv)) as alias)) end run I don't think it's possible to copy more than one file to the clipboard without messing around with Cocoa. Specifically, I believe you need to pass an NSArray of NSURLs to [NSPasteboard writeObjects:someArray].
  3. For any kind of autocompletion, you need a Script Filter. In your case, because you want 2-3 levels of input, you'll need a somewhat complicated Script Filter. There are a few ways to go about doing that. I recommend you start by reading the stickied post describing how to chain Script Filters together.
  4. The file ~/Library/Preferences/com.runningwithcrayons.Alfred-Preferences.plist contains things like the selected theme (appearance.theme) and the path to (the directory containing) the Alfred.alfredpreferences bundle (syncfolder). You can get the values for these preferences using defaults, e.g.: defaults read com.runningwithcrayons.Alfred-Preferences syncfolder Please note: I've always synchronised my workflows between different machines, so I've no idea if the syncfolder preference is present on machines that don't have sync configured. In that case, all workflows etc. should be in ~/Library/Application Support/Alfred 2/Alfred.alfredpreferences.
  5. Marvellous. I'll add your Outlook rules to the next release. Thanks for fixing the issue for other Outlook users.
  6. Okay then. Just using the grandparent directory seems a lot simpler, however. Unless you're working with symlinks.
  7. Maybe, maybe not. I don't have Outlook, so I can't test it. The workflow works very well with non-ASCII text. The problem is almost certainly with Outlook's handling of mailto: URIs. A lot of email programs don't handle them properly and the workflow has specific rules for certain clients. But not Outlook because I don't have it. Some email programs are smart enough to add the name from your Contacts if you just enter an email address. Try changing the Format to Email only in the settings (Enter mailto in Alfred) and see if it works any better. Beyond that, better support for Outlook is dependent on either the Microsoft team implementing better mailto: URI handling or someone else (who has Outlook) figuring out a fix for the workflow. You could try writing your own set of rules for Outlook.
  8. It's supposed to work like the latter case. That's why there's & return & between theTitle and theText.
  9. Your code no longer matches your description. Did you get this problem sorted out?
  10. I don't understand. If you're not running your script from within Alfred, the Alfred environmental variables Vítor mentions above that are "exactly what [you] needed" won't be available…
  11. To clarify my earlier statement, using passwords generated by an online service is a very bad idea; using them as a source of entropy, like your workflow does, is an entirely different matter. Combining multiple sources of entropy is a Very Good Thing™, and a compromised source can't defeat your security if used in the right way.
  12. It's like two or three extra lines of code to use SecureRandom instead and improve the security of the generated passwords. I appreciate and understand your attitude to workflows, but it's not a universal one. As a result, I think it's important that you mention that you don't consider your workflow appropriate for generating super-secure passwords. I also keep all my passwords in 1Password, but I wrote my own generator because I dislike the lack of transparency in 1Password's. There's no indication of how it calculates password strength, and the algorithm (exactly X digits and Y symbols) is a bit suspicious to me. Also, it doesn't support a super-useful technique for generating hard-to-crack passwords: non-ASCII characters. Throw a ü or ø into a password, and it is way more secure (most crackers only use ASCII).
  13. I'm not sure how this is simpler to use than my password generator, but whatever. Unfortunately, your workflow uses Ruby's rand() function, which is not a good source of entropy, and therefore not very secure. You really should use SecureRandom instead, which uses /dev/urandom as a source of entropy (the best you'll get without having the user bang on the keyboard like a monkey). Indeed, a password generator should absolutely not rely on online services, or any other services not under the user's control. Asking a webpage to generate your passwords for you is a very bad idea (unless you know and trust the operator 100%).
  14. property accountName : "iCloud" property folderName : "Notes" -- Return title and URL of current Safari page on getSafariPage() tell application "Safari" set theURL to URL of front document set theTitle to name of front document end tell return {link:theURL, title:theTitle} end getSafariPage -- Add note to Note.app -- the body of the note it theTitle + theText on addNote(theText, theTitle) set theBody to theTitle & return & theText tell application "Notes" tell account accountName set theNote to make new note at folder folderName with properties {body:theBody, name:theTitle} end tell end tell end addNote on run (argv) set pageInfo to my getSafariPage() my addNote(link of pageInfo, title of pageInfo) end run
  15. If you're trying to run AppleScript, you need to set the language to AppleScript, which is indeed the "AS" in /usr/bin/osascript (AS). So, yeah, use that instead.
  16. What is a "/bin/bash Apple Script"? That sounds like a problem.
  17. When Alfred runs your workflow, it always does to from the workflow's own directory. That is to say, from any running workflow, the user's workflow directory is ../.
  18. If you want to run a workflow script without Alfred's GUI, you shouldn't be running it via Alfred… Try calling the script directly. Also, the slowness is probably not due to Alfred. AppleScript is the more likely culprit.
  19. No to both questions, I'm afraid. (1) is beyond the scope of the workflow. (2) Alfred already does that (but I prefer FastScripts).
  20. It's already in there. Please refer to the documentation.
  21. This script gets the URL of the current Safari page and creates a new note in Notes.app containing the URL. Put it in a Run Script action with Language = /usr/bin/osascript (AS), the attach it to a Keyword/Hotkey of your choice. property accountName : "iCloud" property folderName : "Notes" on getSafariUrl() tell application "Safari" to return URL of front document end getSafariUrl on addNote(theText, theTitle) tell application "Notes" tell account accountName set theNote to make new note at folder folderName with properties {body:theText, name:theTitle} end tell end tell end addNote on run (argv) set theUrl to my getSafariUrl() my addNote(theUrl, "URL from Safari") end run
  22. AFAIK, there isn't a workflow to do this. There doesn't appear to be an API, either, to pull search results from. There is a JSON API for search suggestions, which might be acceptable to you (where cellfun is the search query): http://uk.mathworks.com/help/search/json/doccenter/en/R2015b?submitsearch=&qdoc=cellfun If those results are helpful, this tutorial for Python workflows might help you turn them into a workflow.
  23. cURL write its output to STDOUT by default. It's possible that its output is interfering with the notification (e.g. Alfred registers a blank line and ignores it.) Try redirecting cURL's output: curl ... > /dev/null.
  24. Sweet. I think fully-encoded URLs is the only proper thing to do because unencoded URLs are technically invalid and will likely not work in many contexts, e.g. you can't put a URL containing single quotes into href='...'. Seeing as there are already loads of partially-encoded URLs in the wild, I imagine Alfred will still need to do some processing of the URLs to avoid any double encoding.
×
×
  • Create New...