cremoer Posted August 31, 2019 Posted August 31, 2019 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?
dfay Posted August 31, 2019 Posted August 31, 2019 The answer will depend on the app - you’ll need to use Applescript & implementation is highly variable...
cremoer Posted August 31, 2019 Author Posted August 31, 2019 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.
deanishe Posted August 31, 2019 Posted August 31, 2019 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}); }
cremoer Posted August 31, 2019 Author Posted August 31, 2019 (edited) 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 August 31, 2019 by cremoer
deanishe Posted August 31, 2019 Posted August 31, 2019 1 minute ago, cremoer said: It’s a hard to describe app, unlike anything.. I know what Tinderbox is. I don't know its AppleScript API.
cremoer Posted August 31, 2019 Author Posted August 31, 2019 Ah, ok. The API is rather new now, since version 8.0.4 I think.
deanishe Posted August 31, 2019 Posted August 31, 2019 1 hour ago, cremoer said: Btw, you live in Essen? Then we are nearly neighbours, I come from Wuppertal Yup.
cremoer Posted August 31, 2019 Author Posted August 31, 2019 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: 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?
deanishe Posted August 31, 2019 Posted August 31, 2019 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.
cremoer Posted August 31, 2019 Author Posted August 31, 2019 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!
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now