omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Get Workflow Name programmatically

    Editorial
    4
    20
    9759
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • filippocld223
      filippocld223 last edited by

      I am trying to edit some parameters of workflows with python code. i've got the path where the workflows are stored but i don't know how to find the specified workflow because filenames are different than the name given via workflow editor Example: C420F7E7-BB5B-481B-8053-1289FE4E404E.wkflw

      how to find the "correct" workflow name?

      1 Reply Last reply Reply Quote 0
      • omz
        omz last edited by

        The mapping of workflow titles to filenames is stored in a JSON file called Commands.edcmd.

        Here's a snippet of Python code to print titles and filenames for all workflows:

        import editor
        import os
        import json
        
        with open(os.path.join(editor.get_workflows_path(), 'Commands.edcmd')) as f:
        	wf_infos = json.load(f)
        	for wf in wf_infos:
        		print wf['filename'] + ' -- ' + wf['title']
        

        Note that if you want to modify this file (be careful with that!), you have to call editor.reload_workflows() afterwards.

        1 Reply Last reply Reply Quote 0
        • filippocld223
          filippocld223 last edited by

          Oh, Thanks :-)
          ok, i will be careful :-)

          1 Reply Last reply Reply Quote 0
          • filippocld223
            filippocld223 last edited by

            I'm not so pratic with json module :-(

            i want to edit the customTitle of this workflow:

            {"actions":[{"class":"WorkflowActionStoreVariable","pauseBeforeRunning":true,"customTitle":"Lorem Ipsum","parameters":{"name":"variabile","value":{"tokenRanges":{},"type":"advancedText","text":"Some Text"}},"pauseWithoutShowingParameters":false}]}

            How to do that?

            1 Reply Last reply Reply Quote 0
            • omz
              omz last edited by

              Workflow (.wkflw) files are also in JSON format, and it's relatively easy to modify them using the json module, if you know your way around lists and dicts.

              import json
              workflow_filename = 'someworkflow.wkflw' # change this
              
              # Read the workflow data:
              with open(workflow_filename, 'r') as f:
                workflow_dict = json.load(f)
              
              # Modify it:
              actions = workflow_dict['actions']
              first_action = actions[0]
              first_action['customTitle'] = 'Foo Bar'
              
              # Save the modified workflow data:
              with open(workflow_filename, 'w') as f:
                json.dump(workflow_dict)
              

              This will set the custom title of the first action in the workflow to "Foo Bar".

              (Note: this won't work if the workflow you're modifying is currently open in the workflow editor)

              1 Reply Last reply Reply Quote 0
              • filippocld223
                filippocld223 last edited by

                Oh so simply :-)
                excuse me, i don't know the json module very well😔 ,but Thanks :-)

                1 Reply Last reply Reply Quote 0
                • filippocld223
                  filippocld223 last edited by

                  Ok,my work is almost done.
                  Anyway i'd make a page on documentation with more details on the workflow system

                  1 Reply Last reply Reply Quote 0
                  • MartinPacker
                    MartinPacker last edited by

                    I'd quite like a workflow that lists my current workflows and creates an Evernote note based on this list. Probably as a table.

                    The words "quite like" mean it's not likely to bubble up to the top of my fun Development list soon. :-( :-)

                    1 Reply Last reply Reply Quote 0
                    • jonmoore
                      jonmoore last edited by

                      Really useful info in this thread.

                      Not sure how I'd use it yet, but some kind of conditional workflow chaining is the first thing that springs to mind.

                      1 Reply Last reply Reply Quote 0
                      • MartinPacker
                        MartinPacker last edited by

                        I'd like to know if @omz considers the file formats we're talking about as being stable. If so one could build tooling in other places that might prove useful.

                        1 Reply Last reply Reply Quote 0
                        • omz
                          omz last edited by

                          I'd like to know if @omz considers the file formats we're talking about as being stable. If so one could build tooling in other places that might prove useful.

                          It's not very likely that I'll make backwards-incompatible changes, though I'll obviously add things as the workflow system evolves (new action and parameter types etc.).

                          I'd say the format is relatively easy to understand when you pretty-print the JSON, but I don't really plan to document it properly. The workflow editor isn't really prepared for malformed data, and it's quite possible that you'll see crashes or weird behavior when you change a .wkflw file in ways that wouldn't be possible in the UI.

                          If you want to play with "meta" workflows, I'd really recommend making a backup of your workflows first. You can do this with my Backup workflow, which incidentally also demonstrates a practical use case of editor.reload_workflows.

                          1 Reply Last reply Reply Quote 0
                          • MartinPacker
                            MartinPacker last edited by

                            Thanks. That's pretty much what I thought the deal was. I don't, as it happens, have an idea for tooling. I was just very happy this is JSON-based.

                            1 Reply Last reply Reply Quote 0
                            • filippocld223
                              filippocld223 last edited by

                              i was thinking on a self-variable editing workflow
                              i want to add some things on a list but not with a text file.modifying the variables. So funny :-D anyway i won't publish the workflow

                              1 Reply Last reply Reply Quote 0
                              • omz
                                omz last edited by

                                Modifying the workflow that is currently running won't work. It's loaded from the .wkflw file when it's started, but afterwards it's in memory, and won't touch the file again while it's running.

                                1 Reply Last reply Reply Quote 0
                                • MartinPacker
                                  MartinPacker last edited by

                                  If one workflow could kick off another then it could kick off a new instance of itself.

                                  1. Is it possible for one workflow to kick off a new instance of itself (or indeed a different workflow)?

                                  2. Would that indeed reload from the .wkflw ?

                                  1 Reply Last reply Reply Quote 0
                                  • filippocld223
                                    filippocld223 last edited by

                                    @ole it works if the file is not opened in the editor :-)

                                    1 Reply Last reply Reply Quote 0
                                    • filippocld223
                                      filippocld223 last edited by

                                      if you start the workflow without editing it it will work

                                      1 Reply Last reply Reply Quote 0
                                      • MartinPacker
                                        MartinPacker last edited by

                                        Got a sample, @filippocld?

                                        1 Reply Last reply Reply Quote 0
                                        • filippocld223
                                          filippocld223 last edited by

                                          Ok...there it is!
                                          http://editorial-app.appspot.com/workflow/5903508918239232/qfH12Las3wo
                                          but,please don't publish the workflow

                                          1 Reply Last reply Reply Quote 0
                                          • filippocld223
                                            filippocld223 last edited by

                                            .

                                            1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post
                                            Powered by NodeBB Forums | Contributors