I am using an app AMIEngine.app that I created, it takes the action from the AMI URL and uses the app applescript to run the python script to get the action of opening the desired folder. So here is the applescript in the AMIEngine.app, takes the python script:
PYTHON
#!/usr/bin/env python3
import os
import sys
import subprocess
import urllib.parse
from shotgun_api3 import Shotgun
ShotGrid Configuration
SERVER_URL = “removed for this post”
SCRIPT_NAME = “removed for this post”
API_KEY = “removed for this post”
MEDIA_TREE_BASE = “removed for this post”
def get_shot_code(shot_id):
“”“Get Shot code from ShotGrid using the shot ID.”“”
try:
sg = Shotgun(SERVER_URL, SCRIPT_NAME, API_KEY)
shot_data = sg.find_one(“Shot”, [[“id”, “is”, int(shot_id)]], [“code”])
if shot_data and shot_data.get(“code”):
return shot_data[“code”]
else:
print(f"
Error: Shot ID {shot_id} not found in ShotGrid.“)
return None
except Exception as e:
print(f"
ShotGrid API error: {e}”)
return None
def open_shot_folder(shot_code):
“”“Find and open the folder matching the shot code.”“”
for root, dirs, _ in os.walk(MEDIA_TREE_BASE):
if shot_code in dirs:
folder_path = os.path.join(root, shot_code)
subprocess.run([“open”, folder_path])
print(f"
Opened: {folder_path}“)
return True
print(f"
No folder found for ‘{shot_code}’ in {MEDIA_TREE_BASE}”)
return False
def process_shot_ids(shot_ids):
“”“Process a list of shot IDs: fetch their code and open the folder.”“”
for shot_id in shot_ids:
shot_id = shot_id.strip()
if shot_id:
shot_code = get_shot_code(shot_id)
if shot_code:
open_shot_folder(shot_code)
if name == “main”:
if len(sys.argv) < 2:
print(“
Usage: python ami_engine.py <shot_ids_or_url>”)
sys.exit(1)
input_arg = sys.argv[1]
shot_ids = []
# If the argument is a URL (starts with "shotgun://"), parse it:
if input_arg.startswith("shotgun://"):
parsed_url = urllib.parse.urlparse(input_arg)
query_params = urllib.parse.parse_qs(parsed_url.query)
# Expecting the parameter to be named "selected_ids" (e.g. selected_ids=123,456,789)
ids_param = query_params.get("selected_ids", [])
if ids_param:
# ids_param is typically a list with one element like ["123,456,789"]
shot_ids = ids_param[0].split(",")
else:
print("❌ No 'selected_ids' parameter found in the URL.")
sys.exit(1)
else:
# If not a URL, then treat the input as shot IDs.
# If it contains commas, split it; otherwise, use the provided arguments.
if "," in input_arg:
shot_ids = input_arg.split(",")
else:
shot_ids = sys.argv[1:]
if not shot_ids:
print("❌ No shot IDs provided.")
sys.exit(1)
process_shot_ids(shot_ids)
APPLESCRIPT
on open location this_URL
try
– Extract parameters from the URL
set AppleScript’s text item delimiters to “?”
set query to item 2 of (text items of this_URL)
set AppleScript’s text item delimiters to “&”
set params to text items of query
set AppleScript’s text item delimiters to “=”
– Initialize an empty list for shot IDs
set shot_ids to {}
– Loop through parameters to find selected_ids
repeat with param in params
set param_items to text items of param
if item 1 of param_items is “selected_ids” then
set id_list to item 2 of param_items
– Split the id_list by commas
set AppleScript’s text item delimiters to “,”
set id_items to text items of id_list
– Add each ID to the shot_ids list
repeat with id_item in id_items
set end of shot_ids to id_item
end repeat
end if
end repeat
– Ensure we have at least one ID
if (count of shot_ids) is greater than 0 then
– Construct the command to run the Python script with all shot IDs
set shot_id_args to “”
repeat with shot_id in shot_ids
set shot_id_args to shot_id_args & " " & shot_id
end repeat
– Activate the virtual environment and run the Python script
do shell script “removed python script address for this post” & shot_id_args
else
display dialog “Error: No Shot IDs found in URL.” buttons {“OK”} default button “OK”
end if
on error errMsg
display dialog "Error: " & errMsg buttons {“OK”} default button “OK”
end try
end open location
And I’ve tried these URLS: shotgun://ShotgunAMIEngine.app?selected_ids={ids}
shotgun://ShotgunAMIEngine.app?selected_ids=${selected_ids} but as mentioned, it doesn’t open the folders via right click on flow and choosing ‘open folder’, but if I hardcode a record number shotgun://ShotgunAMIEngine.app?selected_ids=1339, it will open the folder of that record (shot) on our server.