Jump to content

[SOLVED] Cycle through instances of app: possible?


Recommended Posts

Hi there,

 

I would like to build a little workflow, where I can choose between the running instances (documents) of an application.

Let's say, there are 3 documents open in one app (in separate windows). Can I build somehow a filter, that shows those opened windows and cycles through them, so that I can choose the one, that I want?

Link to comment

Normally I use JXA and i can address the filenames for example like this: Application("Tinderbox 8").documents.at(0).name().

Now I want to build some filter, that Alfred shows me also documents.at(1), documents.at(2) and so on, so that I can choose from this list, and jump directly to the file, that I want to edit.

Link to comment

I don't know about Tinderbox, but this is generally how you'd build a Script Filter to do that.

app = Application('Safari');

function run() {

	var items = [];

	for (var i = 0; i < app.documents.length; i++) {
		var doc = app.documents[i];
		items.push({
			title: doc.name(),
			arg: i
		});		
	}
	
	return JSON.stringify({items: items});
}

 

Link to comment
3 hours ago, deanishe said:

 

I don't know about Tinderbox

 

It’s a hard to describe app, unlike anything...

Something in between note taking, mind mapping, planning, brain storming and so on. You also could create a website with it or track your expenses... as well as write a novel or plan your tasks. I will have a look on the script Filter in a few minutes, when I am home again. 

Btw, you live in Essen? Then we are nearly neighbours, I come from Wuppertal 🌨😀

Edited by cremoer
Link to comment
  • vitor changed the title to [SOLVED] Cycle through instances of app: possible?

I changed the script a little bit, in that I don't pass the index as argument, but the path of the document as string and furthermore pass this to an "open file" action in Alfred, like so:

app = Application('Tinderbox');

function run() {

	var items = [];

	for (var i = 0; i < app.documents.length; i++) {
		var doc = app.documents[i];
		items.push({
			title: doc.name(),
			arg: doc.file().toString()
		});		
	}
	
	return JSON.stringify({items: items});
}

followed by:

 

image.png.ed2151c83e845e7fbe9a6687e600b8b6.png

 

Works, but does not seem to be the most elegant way. 

Any other / better ideas to make the chosen document the frontmost / focused document in my app?

Link to comment
1 hour ago, cremoer said:

Any other / better ideas to make the chosen document the frontmost / focused document in my app?

 

That depends on the particular application. Like @dfay says, you can do Application('Tinderbox').activate(); to activate the app, but to bring a specific window to the front, you often do something like:

app = Application('Safari');

function run(argv) {
	var index = argv[0];

	if (index != 0) {
		var win = app.windows[index];
		win.visible = false;
		win.visible = true;
	}
	app.activate();
}

That would go in a Run Script action.

Link to comment

Activation of the app is no problem. It’s more, that I want to bring the right document to the front. As I said, the „open file“ action works, although the file is already open. I only thought, there would be some other method. I will try the approach of deanishe... Thanks again!

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...