Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Huge performance improvement #4

Open
AnthoPakPak opened this issue Feb 4, 2020 · 1 comment
Open

Huge performance improvement #4

AnthoPakPak opened this issue Feb 4, 2020 · 1 comment

Comments

@AnthoPakPak
Copy link

AnthoPakPak commented Feb 4, 2020

Hi!

First, thanks a lot for this workflow!

When you begin to have many tasks in Tyme2, the workflow starts to load tasks for ~2-3 seconds. I've tried to improve the AppleScript used to list the tasks, and ended up making a new implementation using JXA. I don't have the time for a PR, so I'm just dropping the code here for anyone who want an instant loading of tasks!

var query = "{query}".toLowerCase();

var tyme = Application('Tyme2');

var xml = "<?xml version='1.0'?><items>"

if ("stop".includes(query)) {
	xml += "<item arg='stop' uid='stop' autocomplete='stop' active='YES'><title>Stop</title><subtitle>Stop running task</subtitle></item>"
}

var allProjectNames = tyme.projects.name();
var allTasksNames = tyme.projects.tasks.name();

nbProjects = allProjectNames.length;
for (var i = 0; i < nbProjects; i++) {
	
	nbTasks = allTasksNames[i].length
	tasksOfThisProject = allTasksNames[i];
	for (var j = 0; j < tasksOfThisProject.length; j++) {
		projectName = allProjectNames[i];
		taskName = tasksOfThisProject[j];
		if (projectName.toLowerCase().includes(query) || taskName.toLowerCase().includes(query)) {
			xml += "<item arg='" + projectName + "|_|" + taskName + "' uid='" + projectName + ": " + taskName + "' autocomplete='" + projectName + ": " + taskName + "'><title>" + projectName + ": " + taskName + "</title></item>";
		}
	}

}


xml += "</items>"

Just replace current AS code with this JXA code (in Script Filter block), and change language to osascript (JS).

Hope someone will find this useful! 😉

@roelvan
Copy link
Owner

roelvan commented Feb 5, 2020

Thanks for sharing! Will try to merge your code somewhere this week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants