Jump to content

Display math equations in Alfred?


Recommended Posts

Hey guys! ;)

First: English isn't my native language, so I'm sorry for some unconventional writing. Secondly: I just started with the amazing capabilities of Alfred Workflows and im not really in that coding stuff, but I will give my best. So be kind of fair with me.^^
---
My goal so far: I want to calculate Stuff via Sympy in Python and display the result in Alfred.

My problem: JSON doesn't support the latex output of Sympy (seems so).

My Question: Is there something I dismiss or just did wrong? Or is there a completly other possibility to do it? 

I will give you a short example of what I did before (it's just like a minimal-example):

 

My Python file:

 

import json
import sys
import sympy as sym
 
args = sys.argv[1]
 
x = sym.symbols('x')
 
result = {"items": [
{
"type": "file",
"title": x,
"subtitle": "... is the solution for the given equation.",
"arg": x
}
]}
 
finalResult = json.dumps(result)
 
print(finalResult)

 

My Script:

 

python3 /Users/ma***/Desktop/temp/testfile.py "{query}"

 

The supposed error as I mentioned before:

 

TypeError: Object of type Symbol is not JSON serializable.

 

Note: I just want no additionally window that opens and that I need to close manually. Something like the AsciiMath did would be okay.

 

I hope you can understand my Problem and we can find a solution!

 

Thanks! :)

Link to comment

Hey Vitor! ;)

That has solved my current problem. Thanks for that!
 

But how its likely, by solving one Problem there comes another across:

 

I have no clue, how I can receive the input from Alfred just as it typed.

Just like: 

 

image.png.f8bd1fbd0ece4744784a030f59fec49c.png

 

(this was manually written down in the Code)

 

But if I try it with that with my code:

 

import json
import sys
import sympy as sym
 
args = sys.argv[1:]
 
x = sym.symbols('x')
y = sym.solve(args,x)
 
result = {"items": [
{
"type": "file",
"title": str(y),
"subtitle": "... is the solution for the given equation.",
"arg": str(y)
}
]}
 
finalResult = json.dumps(result)
 
print(finalResult)

 

it gives me:

 

 image.png.c70b66090454711d88e2290f8f04feff.png

 

doesn't matter what I haved typed in.

 

Debug:

 

[12:19:31.817] Sympy: Solving Equations with 1 unknown Variable[Script Filter] Queuing argument 'x'
[12:19:32.086] Sympy: Solving Equations with 1 unknown Variable[Script Filter] Script with argv '(null)' finished
[12:19:32.089] Sympy: Solving Equations with 1 unknown Variable[Script Filter] {"items": [{"type": "file", "title": "[]", "subtitle": "... is the solution for the given equation.", "arg": "[]"}]}
[12:19:33.494] Sympy: Solving Equations with 1 unknown Variable[Script Filter] Queuing argument 'x+'
[12:19:33.602] Sympy: Solving Equations with 1 unknown Variable[Script Filter] Queuing argument 'x+2'
[12:19:33.699] Sympy: Solving Equations with 1 unknown Variable[Script Filter] Script with argv '(null)' finished
[12:19:33.702] Sympy: Solving Equations with 1 unknown Variable[Script Filter] {"items": [{"type": "file", "title": "[]", "subtitle": "... is the solution for the given equation.", "arg": "[]"}]}

 

The Queuing Argument seems to be right.

 

I have the guess, that the input isn't the right data-type.

 

Hope you can help me once again.

 

Thanks!

 

Link to comment
21 minutes ago, mazerunner said:

in my Script {query} was missing.

 

Avoid with input as {query} in favour of with input as argv. It is the default for a reason: it allows for multiple arguments and you don’t have to worry about escaping.

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...