Welcome, Guest. Please Login
Tinderbox
  News:
IMPORTANT MESSAGE! This forum has now been replaced by a new forum at http://forum.eastgate.com and no further posting or member registration is allowed. The forum is still accessible via read-only access for reference purposes. If you wish to discuss content here, please use the new forum. N.B. - posting in the new forum requires a fresh registration in the new forum (sorry - member data can't be ported).
  HomeHelpSearchLogin  
 
Pages: 1
Send Topic Print
Evaluating the Name of an Attribute (Read 8154 times)
steve harf
Full Member
*
Offline



Posts: 76
Cleveland, Ohio
Evaluating the Name of an Attribute
Feb 26th, 2008, 11:49am
 
I have an attribute (A) whose value is the name of another attribute (B).
Can I create an action that gets the value of the attribute B by evaluating the value of A? What I would like to do might look something like this:

temp = ^value($A)
now temp contains the name of an attribute, "B"
C = ^value($temp)
now C contains the value of attribute "B"

This doesn't work because TB treats the value of temp as a text string and not as a attribute name.  
I know that I can use a lot of embedded ^if statements to test each value of A, but this means spelling out explicitly all the possible values that A might contain.  This gets very "wordy" and sometimes difficult to get correct syntactically.

Any suggestions?
Back to top
 
 

- Steve Harf
WWW steveharf   IP Logged
Mark Bernstein
YaBB Administrator
*
Offline

designer of
Tinderbox

Posts: 2871
Eastgate Systems, Inc.
Re: Evaluating the Name of an Attribute
Reply #1 - Feb 26th, 2008, 3:53pm
 
Your first step could be simpler:   Code:
temp=$a;  



But ^value isn't what you want; it's just a way to glue an expression into an export template and doesn't force an extra level of evaluation.

I think this can be made simpler, but I don't see an trivial solution off hand.
Back to top
 
 
WWW   IP Logged
steve harf
Full Member
*
Offline



Posts: 76
Cleveland, Ohio
Re: Evaluating the Name of an Attribute
Reply #2 - Feb 26th, 2008, 8:05pm
 
Mark, Thanks for the response.

^value , clearly isn't the answer, but since it evaluates expressions it was the closest approach I could find. I will keep at it, but would welcome suggestions of other approaches.

My specific need right now is I want to have different attributes for a variety of URLs (one that has an email address, one that has a web address, one that launches a mapquest map based on address information). For each note I want to set the URL attribute to one of these URL values, so I can launch them easily. (In the interim I suppose I could create a different stamp that would grab one of these attributes and copy the value to the URL attribute.)
Back to top
 
 

- Steve Harf
WWW steveharf   IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Evaluating the Name of an Attribute
Reply #3 - Feb 27th, 2008, 6:54am
 
It sounds as though you want to use URL & ViewInBrowser from within TB to access these URLs. If correct  a stamp for each 'custom' URL' to set that as the URL value. We can also use do() to replace using the export code ^value^ for internal code. I'll assume we've 3 user attributes URL1, URL2, URL3 that hold the URL/email/map data string.

Make 3 macros called set_URL, set_email and set_map; in each case the macro's value is $1. Now make 3 stamps called Set URL with a value URL=do(set_URL,$URL1), Set Email with a value URL=do(set_email,$URL2) and Set Map with a value URL=do(set_map,$URL3).

When you want to set URL for a note or notes, select the note(s) and apply the appropriate TB stamps.  You might consider a stamp to unset URL or simply open Quick Stamp , select 'URL' and click the 'Use default' button.

You could write a shorter simpler Stamp where the value was URL=$URL1 but using the macro do() operator may allow you to tinker a bit more. For instance, you can always pass more parameters into the macro in the Stamp's call, e.g. do(set_URL,$URL1,$MyString) and then use the 2 attributes as $1 and $2 inside your macro.

I've tested the above in v4.1.0 for web URLs & email (I don't know the map protocol); clicking the URL button in a note's sidebar pops the 'URL' in a web browser or opens a new email message as appropriate.

If you're trying to do the above as part of an export to HTML, it would help to understand what triggers the choice of URL value (i.e. have a bit more detail).
Back to top
 
« Last Edit: Feb 27th, 2008, 7:37am by Mark Anderson »  

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
steve harf
Full Member
*
Offline



Posts: 76
Cleveland, Ohio
Re: Evaluating the Name of an Attribute
Reply #4 - Feb 27th, 2008, 3:15pm
 
Mark, Thanks for your suggestions. I have stumbled across a solution that doesn't solve my general problem, but does a nifty job launching URLs. I set up separate stamp for each URL type. Each stamp takes a URL I have stored in an attribute and launches it immediately using the command line.  Mac OS X has a built in Unix command open, which is very handy for opening all kinds of items (URLS, files, applications and folders in the Finder). I have a stamp for each kind of URL, which look something like this:

cmd = `open $UrlEmail

where UrlEmail is an attribute with value like this:  mailto:account@domain.com

I can select a note and execute the above stamp. My email client is opened and a new message is created that is addressed to account@domain.com . There seems to be a limit on the amount of text that can be passed using the "`", so I am experimenting with other approaches, but this one works for most cases.
Back to top
 
 

- Steve Harf
WWW steveharf   IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Evaluating the Name of an Attribute
Reply #5 - Feb 27th, 2008, 4:34pm
 
You might also want to look at the runCommand() operator.
Back to top
 
 

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Evaluating the Name of an Attribute
Reply #6 - Feb 28th, 2008, 6:14pm
 
v4.2.0 now has a new eval() operator for actions allowing the OP's scenario to be complated more easily.
Back to top
 
 

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
steve harf
Full Member
*
Offline



Posts: 76
Cleveland, Ohio
Re: Evaluating the Name of an Attribute
Reply #7 - Feb 28th, 2008, 9:05pm
 
After some experimenting, it appears that both the "`" or runCommand doesn't pass text after the first ampersand "&". So the line

cmd=runCommand( "open mailto:user@example.com?subject=MessageTitle&body=MessageContent")

creates an email message, but the body "MessageContent" is not part of the message. (If I take the identical mailto: line and put it into the URL attribute and launch it it works as it should and puts "MessageContent" in the body of the newly created message.)
Back to top
 
 

- Steve Harf
WWW steveharf   IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Evaluating the Name of an Attribute
Reply #8 - Feb 29th, 2008, 10:54am
 
NB some code example may line wrap on screen but should be entered in TB without line breaks.

You unsuccessfully used:
  cmd=runCommand( "open mailto:user@example.com?subject=MessageTitle&body=MessageContent")

Instead, try:
  cmd=runCommand( "open 'mailto:user@example.com?subject=MessageTitle&body=MessageContent'")

Notice the extra quotes. To give an idea, this doesn't work in Terminal:
  open 'mailto:user@example.com?subject=My name is Joe&body=I live here.'
This works in Terminal:
  open 'mailto:user@example.com?subject=My%20name%20is%20Joe&body=I%20live%20here.'
...your original message didn't have spaces but doubtless someone will want to use them in a similar scenario. Note the use of both double quotes (for TB) and single quotes (for command line).

Figuring your MessageTitle & MessageContent are actually attributes, we need to change things a bit. I had real problems with the '&' character preceding 'body' as it appeared to be truncating the input to runCommand().  I supect the problem was an error on my part of incorrectly terminating string literals (i.e. the bits in double quotes).

This works:
  cmd=runCommand("open 'mailto:user@example.com?subject="+urlEncode($MessageTitle)+"&body="+urlEncode($
MessageContent)+"'")


The following also works and might be better for longer 'body' copy or a more complex string join.  It makes it easier to test the output before it hits the command line:
  OpenStr="open 'mailto:user@example.com?subject="+urlEncode($MessageTitle)+"&body="+urlEncode($
MessageContent)+"'";cmd=runCommand($OpenStr)


It's worth bearing in mind that both TB and the Command Line may have limits on the overal length of the string you can pass though - but I'm not bright enough to know the answer to that one! another user error I tripped over is that passing in empty attribute values (I'd used the wrong name or for got the '$' prefix) will give some odd results. So, when learning this make sure you've got your attributes correctly named and that they have values before you start testing.

My hunch is this sort of code will end up in a conditional statement - if condition X...then create an email. If so it is worth testing the email generation and conditional parts separately before joining the two as it's easier to debug.
Back to top
 
« Last Edit: Feb 29th, 2008, 10:57am by Mark Anderson »  

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
Pages: 1
Send Topic Print