bvp663 Posted June 5, 2013 Share Posted June 5, 2013 Hey Everyone! I have no programming skills so I'm hoping someone can help me with this one. My goal is to extract a portion of a url and copy that portion to the clipboard. Example: http://website.com/customer/uid12345/chats/ I want to create an alfred that either looks at the current url in Chrome or at whatever is copied to the clipboard, and extract the uuid out of that (in this case, 'uid12345') and copy it to the clipboard. At work I have to constantly copy/paste this number from one website into another and it's become tedious. I know there's got to be an easier way and Alfred is the way to go about it. Any programmers out there have any idea of a script or workflow that could make this happen? Link to comment
RodgerWW Posted June 5, 2013 Share Posted June 5, 2013 I'm not sure if this is the exact way you want to go ... I'm new to this, so bear with me: pbpaste | sed 's,http://www.website.com/customer/,,g' | sed 's,/chats/,,g' | pbcopy That above command in terminal will take the contents of the clipboard, i.e.: "http://www.website.com/customer/uid12345/chats/" The sed command will remove the "http://www.website.com/customer/" and also the "/chats/" and then PASTE the remainder of the string to the clipboard. So, you are left with "uid12345" on the clipboard. Basically, you can make a new workflow from Alfred, essentials/keyword to script Double click on the /bin/bash icon or 'Run Script' on the right and in the script area paste the above terminal command. Double click on the left box or 'Keyword' put whatever keyword you want, and select no argument in the right dropdown. Save it. Now, goto the site, select and copy the url ... open Alfred and type your keyword, then paste the results anywhere you wish. This works for ME ... but I am sure someone else could probably come up with something a bit more streamlined or whatever. Link to comment
jdfwarrior Posted June 5, 2013 Share Posted June 5, 2013 I'm not sure if this is the exact way you want to go ... I'm new to this, so bear with me: pbpaste | sed 's,http://www.website.com/customer/,,g' | sed 's,/chats/,,g' | pbcopy That above command in terminal will take the contents of the clipboard, i.e.: "http://www.website.com/customer/uid12345/chats/" The sed command will remove the "http://www.website.com/customer/" and also the "/chats/" and then PASTE the remainder of the string to the clipboard. So, you are left with "uid12345" on the clipboard. Basically, you can make a new workflow from Alfred, essentials/keyword to script Double click on the /bin/bash icon or 'Run Script' on the right and in the script area paste the above terminal command. Double click on the left box or 'Keyword' put whatever keyword you want, and select no argument in the right dropdown. Save it. Now, goto the site, select and copy the url ... open Alfred and type your keyword, then paste the results anywhere you wish. This works for ME ... but I am sure someone else could probably come up with something a bit more streamlined or whatever. Thanks for sharing/helping Roger. Another way this could be done is, if the hid format is constant, you could use a script with a regular expression to grab just it. Also, instead of using pbcopy at the end, you could have also just used the Copy to Clipboard output item in the workflow. Either works, just providing additional options. Link to comment
bvp663 Posted June 6, 2013 Author Share Posted June 6, 2013 Awesome! Thanks guys! The following ended up working (usually I don't have anything after the part I want to copy) pbpaste | sed 's/http:\/\/website.com\/customers\///g' I added "copy to clipboard" as an output for the workflow. Ideally I'd want it to grab the url from Chrome instead of having to rely on copying the url to the clipboard first. I tried GetCurrentURL but didn't have any luck. Any suggestions? Link to comment
jdfwarrior Posted June 6, 2013 Share Posted June 6, 2013 Awesome! Thanks guys! The following ended up working (usually I don't have anything after the part I want to copy) pbpaste | sed 's/http:\/\/website.com\/customers\///g' I added "copy to clipboard" as an output for the workflow. Ideally I'd want it to grab the url from Chrome instead of having to rely on copying the url to the clipboard first. I tried GetCurrentURL but didn't have any luck. Any suggestions? AppleScript to the rescue. tell application "Google Chrome" to get the URL of the active tab of window 1 Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now