arjunrc Posted April 15, 2013 Share Posted April 15, 2013 Hi, I am refining a freeform timezone convertor. It's in perl and I have it working with Alfred as a workflow. I had the following query: To make time conversion easy, I allow the user to define 'mappings'. For example, they can say 'md' maps to 'America/New_York' timezone. Then, they can simply enter: tz 10am md to paris,london,india and it maps all these shortnames to the real timezones and the user won't have to remember them. Now this mapping file can get to several entries. The way I have implemented the workflow is this: As the user keeps typing, I have a script filter that monitors if the input is ready to be sent to my perl script. Then, for each destination (paris, london, india in above example), the script outputs an alfred <item> XML so that while the user is typing destinations, a list of the time calculations show up below. My question now is: Alfred invokes my script each time - so I need to read my mappings file each and every time - is there any way I can 'maintain state' in a way that my script doesn't have to read the mappings file for each new destination? Link to comment
jdfwarrior Posted April 16, 2013 Share Posted April 16, 2013 Hi, I am refining a freeform timezone convertor. It's in perl and I have it working with Alfred as a workflow. I had the following query: To make time conversion easy, I allow the user to define 'mappings'. For example, they can say 'md' maps to 'America/New_York' timezone. Then, they can simply enter: and it maps all these shortnames to the real timezones and the user won't have to remember them. Now this mapping file can get to several entries. The way I have implemented the workflow is this: As the user keeps typing, I have a script filter that monitors if the input is ready to be sent to my perl script. Then, for each destination (paris, london, india in above example), the script outputs an alfred <item> XML so that while the user is typing destinations, a list of the time calculations show up below. My question now is: Alfred invokes my script each time - so I need to read my mappings file each and every time - is there any way I can 'maintain state' in a way that my script doesn't have to read the mappings file for each new destination? If I'm understanding correctly, you have a list of mappings that you read from a file and are trying to load it the first time and not have to continue to load it every time the script is executed? If so, then no there really isn't a way to do this that I can think of. Perhaps it would be easier to just include the mappings in an array in your code rather than having to load it from a file. If done as an associative array then you could simply split the input and use them as an index to access that item directly. Link to comment
arjunrc Posted April 16, 2013 Author Share Posted April 16, 2013 Yes David, that is correct. On the associative array, this file is actually editable - users are encouraged to add their own 'convenience' mappings to timezones. I could devise a mechanism where their inputs are appended to the array, given that its interpretive - in a around about way. thanks - just wanted to make sure I did not miss out any feature of alfred Link to comment
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