Chromium - Using apple script to open URL - applescript

I create a game using html5 based on Chromium project (in Mac). In order to open the game in Chromium, select File menu and select the Open file and browse for the html. And the game is working fine this way
I want to write some script that opens the html in Chromium browser so that I can package it as an application and distribute it as DMG. Has any one come across Chromium script?

Try:
set myFile to "/Users/Satyam/Desktop/OriginalMsg.htm"
do shell script "open " & quoted form of myFile & " -a Chromium"
EDIT
set myFile to "/Users/Satyam/Desktop/OriginalMsg.htm"
do shell script "open " & quoted form of myFile & " -a Chromium"
tell application "Chromium"
activate
close (every tab of window 1 whose title = "New Tab")
end tell

I do not know how to open a url specifically in Chromium. However, normally you do it this way and it will open in a users default web browser. This is the normal way to open files, you don't target a specific application but you let it open in the users' preference.
Maybe it will help you. Good luck.
open location "http://www.url.com"

Related

AppleScript to open a URL from Calendar using Google Chrome depending on the first part of it

I want to make an AppleScript to, if the first part of the link is ____ it will open it in Chrome.
open http://stackoverflow.com -a "Google Chrome"
I got that, but how would I do it depending on the first part of the link.
For example, if the first part of it is https://meet.google.com/xxx-xxxx-xxx to open in Google Chrome.
The xxxxx changes every time.
Alternative solutions welcomed too.
Here is an alternative solution, tested under macOS High Sierra 10.13.6 and it worked:
Automator > New > Service
With settings: Service receives selected text in Calendar
Add a Run Shell Script action, with settings:
Shell: /bin/bash
Pass input: as arguments
Replace the default code with: open "$1" -a "Google Chrome"
Save it as: Open URL in Google Chrome
Then in Calendar, right click on the URL and select Open URL in Google Chrome from the Services context menu.
It's not a single click scenario, but gets the job done.
Without knowing the value for xxx-xxxx-xxx, It's difficult to give an exact answer. I think if you look at the variables I set, This code should give you a good starting point to work with
set baseURL to "https://meet.google.com/"
set openURL to "https://meet.google.com/xxx-xxxx-xxx"
if openURL contains baseURL then do shell script "open " & openURL & " -a 'Google Chrome'"

How to modify MacOS Dock shortcuts/hotkeys?

I want to modify/change/add MacOS Dock shortcuts/hotkeys.
e.g., of a shortcut that is available by default:
Option-Click on Dock app icon of an app that is not currently open = Hide the currently active app and then Open the app that was clicked
(from: https://support.apple.com/kb/PH21922?locale=en_US)
One very specific ability that I want:
Open and then Hide an app
Shift-Click on Dock app icon = Open and then Hide that app
(or use another easy modifier-key-combo with the click)
I am aware of the bash command open -a App --hide (e.g., open -a TextEdit --hide). I want to implement this exact functionality with a convenient Dock shortcut like the one mentioned above. If you're wondering "why?": sometimes I just want to open an app because I know that I will need it soon, but I'm still busy with another app, so just open this second app and then immediately hide it so it doesn't get in my way while I'm still busy with that first app.
How do I do this?
You can't.
These keyboard bindings are built into the Dock application, and cannot be modified.
The Mac utility program, Keyboard Maestro, does what you've asked, with shortcut keys, without using the Dock:
open, then immediately hide/minimize
option+open
I came up with a related solution: (in case anyone is interested)
an AppleScript App that presents a pick list
Method:
create a plain text document containing a list of the apps you want to handle (use correct name, no path, no extension, one name per line, no commas)
open 'Script Editor' (/Applications/Utilities)
copy-pasta the following code (and edit the first code line for the path to your text file from first step)
set apps_file to ("path:apps_list.txt")
set apps_list to paragraphs of (read file apps_file)
set apps_pick to choose from list apps_list with prompt "Select one or more apps." with multiple selections allowed
if result is false then return
set path_base to "Macintosh HD:Applications:"
set path_msft to path_base & "Microsoft Office 2011:"
set path_utly to path_base & "Utilities:"
set spec_msft to "Microsoft"
set spec_utly to "Activity Monitor, Terminal"
repeat with apps_this in apps_pick
if apps_this contains spec_msft
set path_this to path_msft
else if apps_this is in spec_utly
set path_this to path_utly
else
set path_this to path_base
end if
set apps_open to path_this & apps_this & ".app"
run application apps_open
end repeat
return
i. navigate menu 'File -> Export...'; ii. use the option 'File Format: Application'; iii. Save; (put the resulting app in your Dock)
Its not quite as convenient as I hoped, but, not too shabby.

Open link in Firefox via contextual menu using Applescript

I'm new to use Applescript to create services in Snow Leopard. I found myself often trying to open a link in Safari with Firefox. I know there are ways to open a page url with FF but I want to open any link inside a page with FF. I think using Applescript to create a service might be a good idea and so far I found this:
openFirefoxURL("http://www.apple.com/")
on openFirefoxURL(x)
return do shell script "open -a Firefox" & space & quoted form of x
end openFirefoxURL
This creates a new tab in FF nicely. Any advice to adapt it to open a link on a page?
UPDATE: I found a solution through trial and error:
tell application "Safari"
set myURL to (do JavaScript "(getSelection().anchorNode.parentNode.href)" in document 1)
end tell
do shell script "open -a Firefox" & space & myURL
Now that the script serves my purpose, I don't know if there are better ways to do it, e.g. getting the selection via Applescript rather than javascript. Let me know if you have better solutions. Thanks!
There is another approach I just wrote after searching the web for a while an not finding a suitable solution.
It is a service in AppleScript that will open any URL in Firefox from any other application URL field. Just select the text in the URL of Chrome, for instance, and choose the service from the list.
To create the service:
Choose service in the main Automator dialog.
Choose "service receives selected" [URLs]
Choose "in" [any application]
Choose "input is" [only URLs]
Then add the action "Run Shell Script" dragging it to the script sequence.
Choose "Shell" [/bin/bash]
Choose "Pass input" [as arguments]
And paste the following script:
for f in "$#"
do
echo "$f"
if [ ${f:0:4} = "http" ]; then
open -a Firefox "$f"
else
prefix="http://"
prefix+=$f
open -a Firefox "$prefix"
fi
done
The script checks if the "http" prefix is added, as Chrome does not pass it by default, and opens Firefox with the OSX 'open' command.
Save this Service with the name "Open URL in Firefox" and you are done. The service will be available at the services list menu after a right click over any URL field selection.
Done.
The service is saved at ~/Library/Services. This directory is hidden by default in Lion, to see it just issue this command at terminal:
# chflags nohidden ~/Library/
You don't need a special program to do this. Safari already does it. You have to first enable the "Develop" menu in Safari. Go to Safari's preferences, go to the advanced section, and check the box at the bottom called "Show Develop menu in menu bar". Now that you have the Develop menu, you can open any page from Safari in another browser by going to Develop --> Open Page With menu.
So doing that will open the current page in Firefox, then just click on whatever link you want in Firefox.
I'm not sure if I entirely understand what you are trying to do, but if you wish to use Firefox as your default browser, then you don't need Applescript. Just go into Safari, open Preferences, then select Firefox as the default browser at the top of the first tab.
As Safari’s AppleScript dictionary does not provide any way to access the DOM, the JavaScript solution is a pretty good one. If it annoys you to have a service (“Show URL in Firefox”) available even when there is no link in the selected text, I’d recommend Choosy, a helper application / Preference pane by George Brocklehurst which will give you a user prompt for browsers (and much more, up to pattern based selection rules). There is a companion Safari extension which provides the contextual menu option you are looking for.

AppleScript Transmit Script for uploading file to replace itself on web server

So I have this idea for a handy little AppleScript which in my opinion would be very handy in speeding up the process of uploading a local file, to its same location on the server.
In other words, you have to specify the home folder on the server and locally, but once that's finished, it would be nice to just press like "Command" + "Shift" "U" for upload or some other hot key combination not in use by OS X for uploading the currently selected file in the Finder.
I find myself needing to do this a lot, and it will save a lot of time!
Someone please tell me if there is an easier way to do this, but I think this will be a good learning experience on top of it all.
I need some help on how I should get started however..
1) the command line program curl can upload files. 2) if you have a file selected in a Finder window applescript can get the selection. Using those 2 ideas you can automate your task. I don't know the exact curl command but that should be easy to find using google. So you select a file in the Finder and then run the script. The script can be run with a keyboard shortcut as you mentioned or just put it in the Script menu and run it from there.
tell application "Finder"
set selectedFile to item 1 of (get selection)
set selectedFile to selectedFile as text
end tell
do shell script "curl -switchesToUpload " & quoted form of POSIX path of selectedFile
I use Cyberduck which is an ftp client you can set it up so when you double click a file on the server it opens it up in your favorite editor.( textmate is my favorite.) it atuomagiclly downloads and uploads when you save.
this seems like a much better solution to the problem

Open terminal here in Mac OS finder [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Closed 10 years ago.
Locked. This question and its answers are locked because the question is off-topic but has historical significance. It is not currently accepting new answers or interactions.
Is there something similar to the "Open Command Window Here" Windows Powertoy for Mac OS? I've found a couple plugins through a google search but wanted to see what works best for developers out there.
As of Mac OS X Lion 10.7, Terminal includes exactly this functionality as a Service. As with most Services, these are disabled by default, so you'll need to enable this to make it appear in the Services menu.
System Preferences > Keyboard > Shortcuts > Services
Enable New Terminal at Folder. There's also New Terminal Tab at Folder, which will create a tab in the frontmost Terminal window (if any, else it will create a new window). These Services work in all applications, not just Finder, and they operate on folders as well as absolute pathnames selected in text.
You can even assign command keys to them.
Services appear in the Services submenu of each application menu, and within the contextual menu (Control-Click or Right-Click on a folder or pathname).
The New Terminal at Folder service will become active when you select a folder in Finder. You cannot simply have the folder open and run the service "in place". Go back to the parent folder, select the relevant folder, then activate the service via the Services menu or context menu.
In addition, Lion Terminal will open a new terminal window if you drag a folder (or pathname) onto the Terminal application icon, and you can also drag to the tab bar of an existing window to create a new tab.
Finally, if you drag a folder or pathname onto a tab (in the tab bar) and the foreground process is the shell, it will automatically execute a "cd" command. (Dragging into the terminal view within the tab merely inserts the pathname on its own, as in older versions of Terminal.)
You can also do this from the command line or a shell script:
open -a Terminal /path/to/folder
This is the command-line equivalent of dragging a folder/pathname onto the Terminal application icon.
On a related note, Lion Terminal also has new Services for looking up man pages: Open man page in Terminal displays the selected man page topic in a new terminal window, and Search man Pages in Terminal performs "apropos" on the selected text. The former also understands man page references ("open(2)"), man page command line arguments ("2 open") and man page URLs ("x-man-page://2/open").
This:
https://github.com/jbtule/cdto#cd-to
It's a small app that you drag into the Finder toolbar, the icon fits in very nicely. It works with Terminal, xterm (under X11), iterm.
An application that I've found indispensible as an alternative is DTerm, which actually opens a mini terminal right in your application. Plus it works with just about everything out there - Finder, XCode, PhotoShop, etc.
Clarification (thanks #vgm64): if you're already in Terminal, this lets you quickly change to the topmost Finder window without leaving Terminal. This way, you can avoid using the mouse.
I've added the following to my .bash_profile so I can type cdff in Terminal at any time.
function ff { osascript -e 'tell application "Finder"'\
-e "if (${1-1} <= (count Finder windows)) then"\
-e "get POSIX path of (target of window ${1-1} as alias)"\
-e 'else' -e 'get POSIX path of (desktop as alias)'\
-e 'end if' -e 'end tell'; };\
function cdff { cd "`ff $#`"; };
This is from this macosxhints.com Terminal hint.
Check out Open Terminal Here. It may be the most similar to "Open Command Window Here." I used >cdto and this is very similar but this seems to be a little better at dealing with Spaces... but not perfect.
What it has that is very nice is the ability to "detect key-down events at the start of the application and used them to modify the behavior of the script" allowing the script to open a new tab in the front most terminal window when invoked by holding down ⌘ key. Neat trick.
Also note PCheese's answer; it is probably more useful for heavy terminal users!
There is an updated version of the very nice and slim Open Terminal Here posted by vgm64 and d0k. The change was made by james david low. He published the new version on his site. Just download OpenTerminalHere.zip, extract it, move the bundle to your Library/Scripts folder and drag it from there to your Finder toolbar.
What is special about it is that it always opens a new tab if a Terminal.app window is already open. Very useful! I also noted that the style of the button of the application better fits the Snow Leopard Finder.app style than cdto posted by redacted did.
Also, you can copy an item from the finder using command-C, jump into the Terminal (e.g. using Spotlight or QuickSilver) type 'cd ' and simply paste with command-v
I created a bundle with 3 apps for the finder toolbar.
The other two apps do:
open Textmate with the current selection
open GitX with the current folder
For more information see here:
http://nslog.de/posts/71
If you install Big Cat Scripts (http://www.ranchero.com/bigcat/) you can add your own contextual menu (right click) items. I don't think it comes with an Open Terminal Here applescript but I use this script (which I don't honestly remember if I wrote myself, or lifted from someone else's example):
on main(filelist)
tell application "Finder"
try
activate
set frontWin to folder of front window as string
set frontWinPath to (get POSIX path of frontWin)
tell application "Terminal"
activate
do script with command "cd \"" & frontWinPath & "\""
end tell
on error error_message
beep
display dialog error_message buttons ¬
{"OK"} default button 1
end try
end tell
end main
Similar scripts can also get you the complete path to a file on right-click, which is even more useful, I find.
It's a bit more than you're asking for, but I recommend Cocoatech's Path Finder for anyone who wishes the Finder had a bit more juice. It includes a toolbar button to open a Terminal window for the current directory, or a retractable pane with a Terminal command line at the bottom of each Finder window. Plus many other features that I now can't live without. Very mature, stable software.
http://cocoatech.com/
Ok, I realize that this is a bit late... maybe this alternative wasn't available at the moment of writing the post?
Anyway, I've found installing the pos package via Fink (a prerequisite in this case, maybe there is something similar for those who uses MacPorts?) to be the easiest solution. You get two commands:
posd - which gives the current directory of the frontmost Finder window (for which you presumably make an alias cdf=cd posd)
fdc - which switches the current directory of the frontmost Finder window to the Terminal pwd. This is slightly different from 'open .' which always opens a new finder window.
Yes, you have to switch to the Terminal window before writing cdf, but I suppose that's quite cheap comparing to clicking a button in the Finder toolbar. And it works with iTerm as well, you don't have to download a separate Finder toolbar button that opens an iTerm window. This is the same approach as proposed by PCheese, but you don't have to clutter your .bash_profile.
If like me you turn off the Finder toolbar, this Service adds an item to every folder's contextual menu: http://blog.leenarts.net/2009/09/03/open-service-here/
This also allows you to open any folder you see in Finder tree view.
I mostly use this function:
cf() {
cd "$(osascript -e 'tell app "Finder" to POSIX path of (insertion location as alias)')"
}
You could also assign a shortcut to a script like the ones below.
Reuse an existing tab or create a new window (Terminal):
tell application "Finder" to set p to POSIX path of (insertion location as alias)
tell application "Terminal"
if (exists window 1) and not busy of window 1 then
do script "cd " & quoted form of p in window 1
else
do script "cd " & quoted form of p
end if
activate
end tell
Reuse an existing tab or create a new tab (Terminal):
tell application "Finder" to set p to POSIX path of (insertion location as alias)
tell application "Terminal"
if not (exists window 1) then reopen
activate
if busy of window 1 then
tell application "System Events" to keystroke "t" using command down
end if
do script "cd " & quoted form of p in window 1
end tell
Always create a new tab (iTerm 2):
tell application "Finder" to set p to POSIX path of (insertion location as alias)
tell application "iTerm"
if exists current terminal then
current terminal
else
make new terminal
end if
tell (launch session "Default") of result to write text "cd " & quoted form of p
activate
end tell
The first two scripts have two advantages compared to the services added in 10.7:
They use the folder on the title bar instead of requiring you to select a folder first.
They reuse the frontmost tab if it is not busy, e.g. running a command, displaying a man page, or running emacs.
There is a bug in the AppleScript on OSX 10.6. (2 terminal windows open).
I fixed this by adding the close command after activate. This close the first Terminal window.
on run
tell application "Finder"
try
activate
set frontWin to folder of front window as string
set frontWinPath to (get POSIX path of frontWin)
tell application "Terminal"
activate
close
do script with command "cd \"" & frontWinPath & "\""
end tell
on error error_message
beep
display dialog error_message buttons ¬
{"OK"} default button 1
end try
end tell
end run

Resources