Just start by saying I'm not a scripting expert but trying to keep expanding my knowledge. I'm using python to manipulate some pdfs, excel, csv etc via execute command.
I've only used the %1 and %2 system variables for the input and output but I'd like to pass some Switch privatedata keys to the script but I'm not sure how like I do with javascript. Anyone able to help?
Passing switch variable in script
Passing switch variable in script
Color Science & Workflow Automation
- magnussandstrom
- Advanced member
- Posts: 378
- Joined: Thu Jul 30, 2020 6:34 pm
- Location: Sweden
- Contact:
Re: Passing switch variable in script
That sounds like it would work, but really after to to actually write it. I'm going to for sure try this out! Thanks as always.magnussandstrom wrote: ↑Thu Mar 14, 2024 5:10 pm Maybe this is what you looking for?
https://www.enfocus.com/en/appstore/pro ... and-friend
Color Science & Workflow Automation
Re: Passing switch variable in script
I just figured it out and not sure why I spaced it, so posting for anyone else that is self-teaching.
variables are just passed in the command line in the execute command.
example: "path to your script" %1 %2 [PrivateData:Key="yourvalue"]
and then in the script they are done as:
argv[0] is reserved and shouldn't be used.
file_path = argv[1]
output_path = argv[2]
your variable in the script' = argv[3] since I'm on MacOS I Use sys.argv[]
and so on...
variables are just passed in the command line in the execute command.
example: "path to your script" %1 %2 [PrivateData:Key="yourvalue"]
and then in the script they are done as:
argv[0] is reserved and shouldn't be used.
file_path = argv[1]
output_path = argv[2]
your variable in the script' = argv[3] since I'm on MacOS I Use sys.argv[]
and so on...
Color Science & Workflow Automation
-
- Newbie
- Posts: 3
- Joined: Thu Apr 18, 2024 8:04 am
Re: Passing switch variable in script
To pass Switch private data keys to your Python script using the Execute command, you can utilize command-line arguments.
In your Execute command configuration, you can specify additional parameters after the script path and use them within your Python script. For example, if you have a Switch private data key named 'my_key', you can pass its value as a command-line argument like this:
python my_script.py %1 %2 %my_key%
Within your Python script, you can access this argument using the sys.argv list. Here's an example of how you can retrieve the value of 'my_key' within your script:
import sys
# Retrieve the value of 'my_key' from the command-line arguments
my_key_value = sys.argv[3]
# Now you can use my_key_value in your script as needed
print("Value of 'my_key':", my_key_value)
Replace 'my_script.py' with the path to your Python script and adjust the index in sys.argv[] based on the position of your private data key in the Execute command configuration.
hope it helps
In your Execute command configuration, you can specify additional parameters after the script path and use them within your Python script. For example, if you have a Switch private data key named 'my_key', you can pass its value as a command-line argument like this:
python my_script.py %1 %2 %my_key%
Within your Python script, you can access this argument using the sys.argv list. Here's an example of how you can retrieve the value of 'my_key' within your script:
import sys
# Retrieve the value of 'my_key' from the command-line arguments
my_key_value = sys.argv[3]
# Now you can use my_key_value in your script as needed
print("Value of 'my_key':", my_key_value)
Replace 'my_script.py' with the path to your Python script and adjust the index in sys.argv[] based on the position of your private data key in the Execute command configuration.
hope it helps