1. Go into the Workflows panel of Alfred's Settings.
2. Select Firechrome-Workflow.
3. Double click 'Run Script' action.
4. Delete Code and insert
tell application "Firefox" to activate
tell application "System Events"
keystroke "l" using {command down} -- Highlight the URL field.
delay 0.5
keystroke "c" using {command down} -- Copy the URL field.
delay 0.5
do shell script "Open -a 'Google Chrome' " & (the clipboard)
end tell
It's not very fast, but the simplest solution I could find right now. Ok to you?
(sorry for delayed answer, have to figure out how to receive an email when someone quotes me)
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).