In automation forms, how to set focus?

When I generate a form in omnijs, how do I focus on a particular field so that I don’t need to mouse to it?

I am trying to build a plugin where selected projects can be moved to an existing folder, and I populate a dropdown with existing folders. It will be nice if this can be opned automatically making the whole process smoother.

Could you post a minimal working example so we can understand better what you are trying to do ?

This is a full working example. It gets the job done. The irritant is just the need to use the mouse to select the folder.

	/*{
		 "type": "action",
		 "targets": ["omnifocus"],
		 "author": "Abhijit Mahabal",
		 "identifier": "com.amahabal.move_selected_projects_to_folder",
		 "version": "0.1",
		 "description": "This action will move the selected projects to a folder of your choice.",
		 "label": "Move Selected Projects to Folder",
		 "mediumLabel": "Move Projects to Folder",
		 "longLabel": "Move Selected Projects to Folder",
		 "paletteLabel": "Move Selected Projects to Folder",
	}*/
	(() => {
		 var action = new PlugIn.Action(function(selection, sender){
		    var folders = flattenedFolders
		    var folderNames = folders.map(task => {return task.name})
		    var folderRefs = new Array()
		    folderNames.forEach(function (task,index){
		        folderRefs.push(index)
            })

             var selectedTasksMenu = new Form.Field.Option(
                "Folder",
                null,
                folderRefs,
                folderNames,
                0
             )

             var inputForm = new Form()
             inputForm.addField(selectedTasksMenu)
             var formPrompt = "Choose a folder:"
             var buttonTitle = "Continue"
             formPromise = inputForm.show(formPrompt,buttonTitle)

             selectedTasksMenu.focus = true

             inputForm.validate = function(formObject){
                return true
             }

             formPromise.then(function(formObject){
                var folderIndex = formObject.values['Folder']
                console.log('folder: ',folders[folderIndex])
                moveSections(selection.projects, folders[folderIndex])
             })

             formPromise.catch(function(err){
                console.error("form cancelled", err.message)
             })
		 });

		 action.validate = function(selection, sender){
             // validation code
             // selection options: tasks, projects, folders, tags
             return (selection.projects.length > 0)
         };

		 return action;
		})();

image

I just want the dropdown with “Family” selected so that I save a few milliseconds. A function focus() would do the trick, but it doesn’t seem to exist here.

Thanks!

I don’t think I understand what you mean. Probably you know that you can hit Enter and that is the same as clicking Continue right ? So, you don’t have to manually click “Family” because just hitting Enter would execute the action with the name of the folder you are seeing.

If that is not what you want, please clarify or even better show a screen recording.

Thanks, @unlocked2412 , not for this response but for your response on another thread, which made me aware of this:

image

That was off for me. Turning that on made everything work fine. I can imagine how confused my message must have looked :)

I am glad that helped you !

Well, a little bit :)