7.2 KiB
Create protocol Handler
Dienstag, 7. Januar 2020
09:20
Eventuel hier mal schauen :
The portion with the HTTP://,FTP://, etc are called URI Schemes
You can register your own through the registry.
HKEY_CLASSES_ROOT/
your-protocol-name/
(Default) "URL:your-protocol-name Protocol"
URL Protocol ""
shell/
open/
command/
(Default) PathToExecutable
Sources: https://www.iana.org/assignments/uri-schemes/uri-schemes.xhtml, http://msdn.microsoft.com/en-us/library/aa767914(v=vs.85).aspx
Aus <https://stackoverflow.com/questions/389204/how-do-i-create-my-own-url-protocol-e-g-so>
l
Google Whitelist damit nicht mehr die Abfrage kommt wegen öffnen einer Lokalen Application
You can manually whitelist applications/protocol by adding a registry key for it (windows-only)
Create a txt document with the info below in it and import into the registry. The users will no longer see the prompt.
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Google\Chrome\URLWhitelist]
"9"="reciever://*"
"13"="ms-word://*"
"14"="ms-excel://*"
Source:
Aus <https://support.google.com/chrome/thread/14322141?hl=en>
Registering a protocol on Windows
On Windows, registering protocol handlers involves modifying the Windows Registry. Here is a generic example of what you want the registry key to look like:
HKEY_CLASSES_ROOT
foo
(Default) = "URL:foo Protocol"
URL Protocol = ""
shell
open
command (Default) = "foo_path" "%1"
The target URL would look like:
foo://host/path...
Note: For more information, please see http://msdn.microsoft.com/en-us/library/aa767914(VS.85).aspx.
Windows QT/QSetting example
If the application you are developing is written using the QT (or PyQT / PySide) framework, you can leverage the QSetting object to manage the creation of the registry keys for you.
This is what the code looks like to automatically have the application set up the registry keys:
// cmdLine points to the foo path.
//Add foo to the Os protocols and set foobar to handle the protocol
QSettings fooKey("HKEY_CLASSES_ROOT\\foo", QSettings::NativeFormat);
mxKey.setValue(".", "URL:foo Protocol");
mxKey.setValue("URL Protocol", "");
QSettings fooOpenKey("HKEY_CLASSES_ROOT\\foo\\shell\\open\\command", QSettings::NativeFormat);
mxOpenKey.setValue(".", cmdLine);
Windows example that starts a Python script via a Shotgun AMI
A lot of AMIs that run locally may opt to start a simple Python script via the Python interpreter. This allows you to run simple scripts or even apps with GUIs (PyQT, PySide or your GUI framework of choice). Let's look at a practical example that should get you started in this direction.
Step 1: Set up the custom "shotgun" protocol
Using Windows Registry Editor:
HKEY_CLASSES_ROOT\\shotgun
@="URL:shotgun Protocol"
"URL Protocol"=""\
HKEY_CLASSES_ROOT\\shotgun\\shell
HKEY_CLASSES_ROOT\\shotgun\\shell\\open
HKEY_CLASSES_ROOT\\shotgun\\shell\\open\\command
@="\"python\" \"sgTriggerScript.py\" \"%1\""
This setup will register the shotgun:// protocol to launch the python interpreter with the first argument being the script sgTriggerScript.py and the second argument being %1. It is important to understand that %1 will be replaced by the URL that was clicked in the browser or the URL of the AMI that was invoked. This will become the first argument to your Python script.
Note: You may need to have full paths to your Python interpreter and your Python script. Please adjust accordingly.
Step 2: Parse the incoming URL in your Python script
In your script you will take the first argument that was provided, the URL, and parse it down to its components in order to understand the context in which the AMI was invoked. We've provided some simple scaffolding that shows how to do this in the following code.
Python script
import sys
import urlparse
import pprint
def main(args):
# Make sure we have only one arg, the URL
if len(args) != 1:
return 1
# Parse the URL:
protocol, fullPath = args[0].split(":", 1)
path, fullArgs = fullPath.split("?", 1)
action = path.strip("/")
args = fullArgs.split("&")
params = urlparse.parse_qs(fullArgs)
# This is where you can do something productive based on the params and the
# action value in the URL. For now we'll just print out the contents of the
# parsed URL.
fh = open('output.txt', 'w')
fh.write(pprint.pformat((action, params)))
fh.close()
if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))
Step 3: Connect the Shotgun interface with your custom protocol and ultimately, your script
Finally, create an AMI in Shotgun whose URL value will be shotgun://processVersion. You can assign this AMI to any entity type you wish, but this example uses the Version entity.
Go to a Version page, right-click on a version and select your AMI from the menu. This should make your browser open a shotgun:// URL which will be redirected to your script via the registered custom protocol.
In the output.txt file in the same directory as your script you should now see something like this:
('processVersion',
{'cols': ['code',
'image',
'entity',
'sg_status_list',
'user',
'description',
'created_at'],
'column_display_names': ['Version Name',
'Thumbnail',
'Link',
'Status',
'Artist',
'Description',
'Date Created'],
'entity_type': ['Version'],
'ids': ['6933,6934,6935'],
'page_id': ['4606'],
'project_id': ['86'],
'project_name': ['Test'],
'referrer_path': ['/detail/HumanUser/24'],
'selected_ids': ['6934'],
'server_hostname': ['patrick.shotgunstudio.com'],
'session_uuid': ['9676a296-7e16-11e7-8758-0242ac110004'],
'sort_column': ['created_at'],
'sort_direction': ['asc'],
'user_id': ['24'],
'user_login': ['shotgun_admin'],
'view': ['Default']})
Possible variants
By varying the keyword after the // part of the URL in your AMI, you can change the contents of the action variable in your script, all the while keeping the same shotgun:// protocol and registering only a single custom protocol. Then, based on the content of the action variable and the contents of the parameters, your script can understand what the intended behavior should be.
Using this methodology you could open applications, upload content via services like FTP, archive data, send email, or generate PDF reports.
Web.config eventuell ergänzen
iis erweiterung prüfen