Could you please still explain anyway why the extra quotes appear in the output from @alltiagocom's macro? I can smell that there is logic to it all but I haven't worked it out yet...
I note with interest that if the second "Tiago" is renamed "Tiago2", the output is:
This is what I would assume is the logical approach, but this is something I encountered more than once. When you change the variable from Local_list to Local_listItem, it doesn't process. So this seems to be a bug itself.
Logically, I would assume that I need to search the variable "Local__listItem", because that's what I'm processing at the moment, but it only works with "Local__list".
As you can see, using the exact same actions with both examples, I get different results, even though it processes them while using "Local__list"
Exactly. If it wasn't working at all by using Local__list instead of Local__listItem then none of the options would work, which is not the case.
And if it was indeed processing things twice by using the Local__list, then it would add the quotes to the beginning and end of the second example. That's the first issue.
The second issue is that using Local__listItem as we would expect it to be logically, doesn't work at all, only when using the variable that contains the full list, Local__list
This is something I noticed a while ago and it made no sense to me.
If I'm checking a specific line, I should be using the variable defined at the top of the For Each, not the variable with the full list.
(It takes time to set things up from 'seeing' here, and risks extraneous variations )
( experiment is the only source of knowledge – nullius in verba )
In the meanwhile, two things jump to the eye:
Your entry in the Regular Expression field looks odd (would a plain string search suffice ?)
Does the target (Source) make sense ?
Another approach might be to start with a blank target accumulator variable, and
for each line in the source, append a modified copy of local_listItem to the target.
Yes my main goal is that. I appreciate you sharing it.
I was trying it with AppleScript first and for some reason I can't make it work.
I will create a thread just for that, because I want to understand what the issue is, even if I use your macro. I always like to learn a bit more of AS.
Now:
1 - Can you explain what your script is doing?
2 - We still should figure out why my macro is adding those extra quotes and comma
3 - We should also check if in fact using the Search and Replace while using Local__list is a bug or not, instead of using Local_listItem, because it seems like it.
use framework "Foundation"
on run
nub({"Tiago", "Paulo", "Miguel", "Tiago"})
end run
-- nub :: [a] -> [a]
on nub(xs)
((current application's NSArray's arrayWithArray:xs)'s ¬
valueForKeyPath:"@distinctUnionOfObjects.self") as list
end nub
This would be my ultimate goal, yes (or maybe without the {}, because I don't know how the AppleScript is processing the line I have:
set formattedText to {"Tiago", "Paulo", "Pedro", "Tiago"}
So when using a variable, should I use it like this:
set formattedText to {myVar}
assuming that my variable doesn't include the {}
or like this
set formattedText to myVar
...assuming that my variable DOES include the {}
?
Or would that be the same thing?
Basically what I'm trying to achieve in the end, can be achieved using your JavaScript (initially I saw it as shell, my bad)
I just started with AppleScript and I'm trying to figure out why it isn't working, so I can learn something else in the process.
I think I figured it out, based on your suggestion of using another variable, like this:
So when we use the Search and Replace action and set it to "Source", the Local__listItem doesn't work in the "Search Variable" field, but Local__list works, but with that issue with the commas and quotes
When set to send it to another variable as you suggested, it works with Local__listItem as expected, but with Local__list outputs this:
which seems weird, because it's adding commas and quotes around Tiago, both versions, but nothing else...
So it's kinda weird how this is working (or not working)
It's already a sunsetted language, there has been no development work on it for years now, it lacks a lot of the basics, and with every macOS release, it seems to be injured fractionally more.
I've personally had a lot of fun with AppleScript, but I wouldn't really recommend it to anyone as a starting language now.
You wouldn't prefer to learn some JS, which is useful on iOS and the web, as well ?
I can learn that as well, but if AS is still around, even if not as much as JS, wouldn't it be wise to learn a bit more? Do you think AS will be completely abandoned anytime soon?
I'm no developer and I don't plan on being. I learn as I go, mostly because of KM, so learning lots of different languages when I don't use them on a daily basis (I'm a musician, by the way), will probably be not as productive.
I started learning JS maybe 1-2 years ago and because I don't use it on a daily basis, I pretty much forgot 99.9% of it
For example, since you already know AS, it's not a big issue, because even if you learn a new language such as JS, most of the AS knowledge will still be there no matter what. Like riding a bicycle. In my case it would be a bit more complicated and I wonder if AS will be completely abandoned or just used less than other languages and if it makes sense to completely stop learning AS?
Would you confirm that JS can do everything that AS does (and more)? Or is there anything that still needs AS?
Again, if I'm learning a new language, especially because I'm still new to AS, and if JS is capable of what AS does, and more, then yes, I might as well just put AS to the side and start learning JS.
As I mentioned, I'm not a developer and won't be, so I rather focus on learning something I see myself using on a regular basis so I won't forget how things work, you know what I mean?