make a string composed of multiple variables into a variable

Hello hhas.

First of all, Nigel Garveys solution is serializqble, and yours aren’t right out of the box, so what solution that is best in every circumstance isn’t quite so.

I have read what you have written.

Well, other languages have libraries, like Python for instance, and the result of that is that basically “anyone”, sorts an array of three integers with Quicksort.
Doing so on the command line is one thing, doing so by AppleEvents is a whole other story.

I should really written something that that it would be hard to prevent newcomers to misuse the library. I guess.

For libraries to be good to use for new users, they’ll have to pretty much insulate the users from the diversity of for example file specifiers, I have written such a handler that I have posted here, when you have been around with AppleScript for some time, then you know that this handler is ok to use for a single retrieval of a posix path, now a new user might be using the same handler for retrieving a listing of the files that are in some subtree on his disk. Furthermore even if this part of the story is ok, and can be documented, that doesn’t alleviate the fact, that the same checks might be one over and over again, in a script, because of the nondiscriminant use of library handlers which all performs the same tests for class conformance, and god knows what and what not, in order to be as robust and user friendly as possible. This hypothetical end user’s script, will run considerably slower than someone who knows what they are doing, because they know they can test just once, and make it run as fast as possible, which is part of Apple’s philosphy, that software should be fast and efficient. That is quite the opposite take than many other of the industry leaders, where “buy better hardware” is the slogan.

The other reason for not liking the idea, is that it may lead to entrepeneural souls, who hardly knows what they do, to ship apps in the Appstore. Actually, I can’t decide whether I think Javascript apps, that uses libraries, like Popcorn Time app, and ASOC apps, should be banned from the Appstore, or have a warning on their product page, that informs of what they are made of, and that they may reduce the responsiveness of the computer.

The problems I see with AppleScript libraries, other than the bloat, is first and foremost problems with dependencies and versioning of the libraries.

Many of the great libraries out there, has some kind of funding, either in man hours, or cash, from some corporation, and the corporation, isn’t doing that for altruistic purposes, even though, some funding may be granted by Google Summer of code, having a good application. Because funding is needed, in order to establish a library of some size, because of managment, versioning, Q&A, and all that.

And actually, I think at lest AppleScript “2.3” was a great step in the right direction, this works for me. The Google page rank algorithm has been remarkably good, which is why there are less traffic on most forums nowadays, because people can read, and rather read, and solve their problems themselves, than sitting and waitng for some answer. I am not the only one, that google for solutions, I find something, either directly usable, or something I can tweak to work, all done, I drop it into the Script Libraries folder, and “voila”.

There are tons of scripts out there, not only here, but at MacOsXAutomation, there are scripts at specialized app forums, at MacDevCenter, and MacTech, there are zillions of scripts at github and most problems have been solved in some forumpost before anyway, with code to snag.

Also, when I hear the word centralized repository, I kinda hear the word “committee”. And then I start thinking of self promoting power hungry people who are highly opiniated, and sees it as their duty to enforce their taste, opinons and perceptions on what is good and bad. You’ll often see them speak in a very self confident, self promoting, absolute manner, when dealing with subjects they at least think they are the sole experts on. The “Soup Nazis”.

C was a nice language before the Ansi committee established a standard, I have that standard annotated in my shelf, and it covers the language and the standard libraries, in some 600 pages I believe.

A worser example is of course C++.

I make a lot of code freely available, it is just up to people to find it, if they need it, I don’t push it onto them. The code stays at Macscripter, we do have a good environment here, and this is centralized enough for me. The only alternative I see, is the one everyone elses uses, and that is to post the code on their own blog, and that works too, I’d of course contribute code to a central library, if there were any interest in that, on an “as is” basis, and that it won’t be printed/written about in some book. :wink:

Personally, I have nothing against sharing code I have produced for my own consumption, and helping people, when I can. I read the above, as to commit to something, so it would become more of an open source project, and that is not for me, because that means I will have to commit time.

Luckily, we are on OS X, and we do have ASOC, and Shane Stanley has provided a framework, I believe everybody, at least on Yosemite can use. I think any form of Library should start with that framework, or that users that needs solutions should download it.

(I wrote “Soup Nazis”, and not Nazis)

I guess that is a general you of sorts, that you don’t mean that people who have spent many an hour, learning it, scripting scripts, are some kind of assholes, since we don’t find the time, to really push it into the arms of those that have chosen not to put in the effort, knowing that there was a large probability for it beeing for nought anyway?

I regard my self more of an eternal student, than a high priest, and frankly I know no high priests, not here anyways, we all learn some bits, some more often than others, and I think you’d be rather “special”, if you are motivated to “hand out” “trinkets of code”, like some kind of power exchange, instead of being helpful. I don’t really see any ulterior motifs in people here,most of them anyway, but a sheer will to help out fellow citizens.

Dictating? The web is still free, if you choose not to use Google, nobody hinders you really, the thing is, especially with Google, that they happened to have a great product, at the right time, and somewhat had some luck and a theft for business, and ended up in an almost monopoly situation. I bet you have kept ownership over your book, or have you opensourced it? Would you have complained, if your book was so good, that it acquired a monopoly in the AppleScript book market?

You still use a Mac when you bought it, you bought more than that, you bought a whole concept, but I guess you as well, feel that the benefits are greater than the opposite. And that should the day come when you figures it to not be so, that you jump the bandwagon.
Besides that, I like Apples iCloud, it is great for sharing data among devices, and it provides as much privacy as is nowadays.

Yeah, you are one of them lowly users, that just happens to have written a book about the subject and peekd deep into the interals.

I see myself more as a student of AppleScript, and share my knowledge, and learn from others, not necessarily in the same process. And yes, process it is, and we more often end up with some truth and deeper understanding than mot. Most of the time, the tone is frienly, and we are aside of the blogosphere, so there is little self-marketing or “upmanship” here.

And you don’t need reply, because I am done with this subject now. :wink:

Then stop complaining as if you can’t understand why. You keep making it personal and calling people names, in public where you know they can’t answer back, so playing the victim doesn’t wash.

I’m in no position to judge one way or the other, and really, I could care less. But I think that if anyone is interested in the question, they’ve probably heard your opinion already. Many times.

Really? C more difficult or worse than AppleScript :lol:

Hello.

It was really about the Standard libraries and not the language, you still had the lint program, which really did the grunt of the job of issuing warnings, that gcc or clang does today.

C is a very small language, and not difficult at all, compared to AppleScript, The libraries, and all the unforgivness, sort of made the language and libraries bigger, but the code safer. C was actually a lot like AppleScript before, you could ignore return values, without casting to void. The default return value, was the platform specific signed int, which also was the size of a pointer (unsigned int). Easy to use, as long as the programs didn’t become too large. :slight_smile:

I’m using a linter when writing AppleScript as well, so that’s not really an valid argument.

Of course, you don’t rate the difficulty of a language based on it’s syntax (alone).

Hello.

What is “worst” in your opinion? :slight_smile: (We were talking about libraries really, and it all depends on what you write of course, it is a difference in using stdio.h, in comparison with unistd.h for example.

And I think a linter for AppleScript is very different from lint in C, due to the difference in language, and the “type lessness” of AppleScript.

And I don’t know what you are heading out, it is taken out of context, it was really about libraries, and as I wrote above, I am really done with this thread. This is kind of futile to discuss, and it wasn’t what the thread developed to be about anyway. The languages aren comparable at all, and what you and I may mean about the two languages in this forum, is irrelevant? :slight_smile:

I disagree.
First of all, by definition C is a programming language, AppleScript is a scripting language.
The C terminology is much more technical than AppleScript. On the other hand AppleScript is much easier readable “ for amateurs “ like a real language

For example

for int i = 0; i < 10; i++ {} 

vs.

repeat with i from 1 to 10
end repeat

Even the zero-based index is “unnatural”

And if you have to deal with malloc, sizeof etc. or pointers C gets really complicated

I wrote above that it wasn’t comparable really (added it on later), and I also tried to mention, that C was brought onto the table when we discussed libraries.

There are certain things that helps with pointers, and that is the “right hand rule” for pointer casting, thing is, I was mentioning K&R C and there was a lot less casting necessary there, since everything was ints. Of course you’d have to cast in order to return a pointer to function that takes two ints and char * as arguments, and returns an int, for instance.

I agree about the differences, once it is in your fingers, you really didn’t have to look up so much, you could paste the function declarations right into your source file for easy lookup.

I even didn’t mention malloc, I hinted though in the direction that it of course is dependt on what kind of programs you write when I wrote about the difference between using stdio.h and unistd.h, but still today with Ansi-C it is very easy to break string boundaries, (but the compilers have become a lot better in diing such checks, I love Clang, and you have tools like valgrind that monitors memory usage of programs, to find leaks, as “leaks” do.

But I still doesn’t see the relevance of discussing this here, since this is about AppleScript. :slight_smile:

(What I have gotten out of this mentioning of linting is that I want a lookup function in the AppleScript edtiors, that brings me right to the declaration in the library file. :wink: )

The linter I have written will validate in real time and flag the code if needed. How they are technically different doesn’t really matter to me, they are both doing the same job.

Sounds like a great idea. :slight_smile:

I agree that the most important thing is to get the job done. What do your linter do? What kind of flaws does it catch, in addition to the compile time errors that the AppleScript Editors catch?

Edit

I’m curious, unassigned variables, is one thing I can come up with, that would be nice to have, but then again, maybe, if I started to paste instead of writing the variables, then maybe I don’t have to write something that checks for just that. :slight_smile:

  • I can’t think of anything more annoying than run time errors caused by misspelled variables.

I write most of my code in SublimeText3, including AppleScript. So it’s actually a PyObjC script as an plugin for my multi language editor. At first it started out as just running compileAndReturnError method of NSAppleScript object and translate the character range returned into lines and columns like normal code editors do. The line of code having the error will be highlighted, the gutter will have a red dot and the characters that are causing the error will be underlined with a color. Also at the bottom of the screen there will be shown the NSAppleScriptErrorBriefMessage string. But it didn’t take long before it became a work in progress, where those “duh” moments are warned before running actually the code.

Hello.

I see, well, Script Debugger has PCRE regexp support builtin, (though it is awfully slow backwards), so maybe I’ll figure out something, it should be really easy with PCRE, or at least simpler. :slight_smile:

Edit
It doesn’t seem like I can script a search in ScriptDebugger, not at first glance anyway, but what I can do, is to get at the source text, and pass it somewhere else!

TextWrangler is always open, and it has PCRE that are scriptable thru commands that I think I now the most quircks of by now, it searches reasonably fast too, then I can just filter the list, and look for unique variable names. :slight_smile:

More

Script Debugger uses ICU, just to be correct, not interesting, really, since I cant peform a search in a script window with it, but, that is what it uses. (Old version by now.)

Hey McUsrII,

No. I’ve asked Mark to make that available, but so far he has declined.

I use the Satimage.osax to find things. It’s very fast, and SD’s selection is scriptable of course.

Here’s a working example that finds the next marker “–»” after the cursor.

------------------------------------------------------------------------------------------
# Auth: Christopher Stone <scriptmeister@thestoneforge.com>
# dCre: 2012/09/14 06:55
# dMod: 2014/11/02 14:47
# Appl: Script Debugger
# Task: Find the next Marker
# Libs: None
# Osax: Satimage.osax { http://tinyurl.com/dc3soh }
# Tags: @Applescript, @Script, @Debugger, @Script_Debugger, @Find, @Marker
------------------------------------------------------------------------------------------

try
	
	set myPath to (path to me as text)
	
	tell application "Script Debugger"
		if myPath = (get file spec of front document as text) then
			set scriptDoc to a reference to document 2
		else
			set scriptDoc to a reference to document 1
		end if
		
		if scriptDoc exists then
			tell scriptDoc
				
				set _SRC to source text
				set _mark to "^[[:blank:]]*--».*\\s?"
				
				if (fndBool(_mark, _SRC, false, false, false) of me) = true then
					try
						set {startPos, null} to character range of selection
						set fRec to fnd(_mark, _SRC, startPos, false, false, false) of me
						if fRec ñ‰  false then
							set selection to {(matchPos of fRec) + 1, matchLen of fRec}
						else
							set startPos to 0
							set fRec to fnd(_mark, _SRC, startPos, false, false, false) of me
							set selection to {(matchPos of fRec) + 1, matchLen of fRec}
						end if
					end try
				end if
				
			end tell
		end if
	end tell
	
on error e number n
	stdErr(e, n, true, true) of me
end try

------------------------------------------------------------------------------------------
--» HANDLERS
------------------------------------------------------------------------------------------
--  Custom: fnd() is using start-position.
------------------------------------------------------------------------------------------
on fnd(findStr, srcData, startPos, caseSensitive, allOccurrences, stringResult)
	try
		set findResult to find text findStr in srcData starting at startPos case sensitive caseSensitive ÂŹ
			all occurrences allOccurrences string result stringResult with regexp
		return findResult
	on error
		return false
	end try
end fnd
------------------------------------------------------------------------------------------
on fndBool(findStr, srcData, caseSensitive, allOccurrences, stringResult)
	try
		set findResult to find text findStr in srcData case sensitive caseSensitive all occurrences allOccurrences ÂŹ
			string result stringResult with regexp
		return true
	on error
		return false
	end try
end fndBool
------------------------------------------------------------------------------------------

Hey Folks,

Hasn’t this thread gotten rather off-topic?

Why not sprout some new threads for different conversations?

FYI, Cocoa has built-in support for ICU regEx, and has since 10.7, so that’s what most apps are likely to use these days. So if you want to use the same patterns both for scripting SD and in its interface, you could use something like this:

use scripting additions
use framework "Foundation"

on searchForPattern:thePattern
	-- build regEx
	set {theRegEx, theError} to current application's NSRegularExpression's regularExpressionWithPattern:thePattern options:0 |error|:(reference)
	if theRegEx = missing value then -- faulty pattern
		display dialog "Error: " & (theError's localizedDescription() as text) buttons {"OK"} default button 1
		error number -128
	end if
	-- get contents and selection
	tell application "Script Debugger"
		set theString to source text of document 1
		set {loc, len} to character range of selection of document 1
	end tell
	set startPoint to loc + len - 1 -- start immediately after selection
	--search
	repeat -- so we can loop back
		set theFind to theRegEx's firstMatchInString:theString options:0 range:{location:startPoint, |length|:(length of theString) - startPoint}
		if theFind = missing value then
			set theResult to (display dialog "No match found. Start from the beginning again?")
			if button returned of theResult = "OK" then
				set startPoint to 0
			else
				error number -128
			end if
		else -- found it, so exit
			exit repeat
		end if
	end repeat
	-- get range and select in SD
	set theRange to theFind's range()
	tell application "Script Debugger"
		set character range of selection of document 1 to {(location of theRange) + 1, |length| of theRange}
	end tell
end searchForPattern:

Hello.

Chris, I totally agree about off topic, but now it is about Applescript and thanks for the handlers.

And thanks to you Shane. They will certainly come in handy, and they certainly looks hell of a lot better than using ICU from C where you have to handle wide characters as well, as the rather cryptic return values of ICU, when using it from C.

It is no easy task to write something that is reliable for figuring out which words are only written once in a reliable way, due to the way scope and visibility works in AppleScript. I’ll have to work some on this I have no idea of what to use for solving the problem at the moment however[1]. I’ll have to figure out the steps first, then how I have to compensate for “outward scope”, and maybe I along the way figurees that more accurate reading of the most code is the way to go anyway! :slight_smile:

There is one thing that I definitively will write a check for, and that is unique variable names in try-blocks! And I am not too concerned if I over report some when checking those. Better be safe than sorry.

But the problem as I see it, and as I know how linters work, is that you can become numb of all the messages, and you start to ignore the output, because of the overreporting, and you just stop using it, and are back to square 1.

[1]
I have thought that maybe the recursive regexps of BBEdit and perl 5.6 may come in handy, as will shell tools like tr, and sort or unique, for building unique lists of words, maybe egrep for removing all the reserved words in one go. Maybe awk can be used to wade through scopes as well, and well, C can be used for writing a "shell around the source text part to figure out the pieces, and so can perl, maybe even better, since it handles regexps much better, and then maybe use Shane’s handlers back in the editor, when it is about to mark those items.

It is a non trivial task, don’t hold your breath.

More Edits

C has the advantage, that I actually can build a parse tree in memory at some stage, with parent-child relationships, so I can test for “outward scoping”, of say script objects towards the root node, I can also test for “inward visiblity” of properties and handlers in included script objects.

And more
C has also access to tools like lex (lexical analyzer), and yacc (yet another compiler compiler), that you can write grammar expressions for in BNF format (Backus Naur), with regular expressions to parse.

I may be back in some other thread, one day, with something, at least parts of what has come up. Yesterday, I for instance fixed the code completion in Script Debugger, and will use code completion adamently for the future. (Misspellings) :slight_smile:

Use preg then :slight_smile:

Linters are not designed for developer who isn’t disciplined, lazy and doesn’t take programming seriously. Those are the rotten apples in the programming community. So for those few I don’t see this as a problem, any IDE is a waste to them. I agree there is a problem with linters but on a different level. People start to program in such a matter that they will change their code to get rid of the warning without regards of knowing what they are actually doing. They assume when the linter warning is gone they have written their code correctly.

Hello DJ.

Well, there isn’t really any alternatives to ICU, when it comes to regexps with wide characters, and unicode support, I had a round up of contestants, before I picked my choice, and at that moment, some years ago now, I wasn’t fully aware of Apple’s reliance on it either. BBEDit, uses a good PCRE library, but I think you’d have to licence it, in order to use it.

I am not sure if rotten apples is the correct term. :slight_smile: I would’ rather say unconcious about Q&A, and how to improve it. The problem with AppleScript, versus a compiled language, is that is very hard for the AppleScript compiler to know what can be reseolved run-time, and what not, due to the resolving of terminology, and maybe scope. What should the AppleSCript do with right - hand values inside a tell block of some application for instance?

The problems you may introduce in AppleScript, isn’t possible in something like Xcode, because undefined errors, triggers an error, and the whole compilation process is then halted. That some ignorant people follow a “if it compiles - ship it”, philosophy, is another matter, those are rotten apples, and actually, if you don’t add a pragma to surpress a warning from clang for instance, then the probability of the code being correct, when you have compiled it it WEverything, is quite large, if it compiles without a warning. (I do that.)

I work a whole lot, and sometimes, things do slip by. This thread has helped me, to analyze, and improve the consciusness of what I can do better for the future, giving no guarrantees, that I will never post a runtime bug again.

Regression testing, that is too costly for me, being a one man gig, maybe taking up the apps, that I use to work with.

The alternative, is actually to stop sharing code, which I wouldn’t like, because on of the things justifying writing it in the first place, is that I can share it, it feels kind of insane, to write something for a couple of hours, if I am the only one to save some seconds using it. However, if other people uses it, and they saves some seconds too, then the ‘bang for the buck’ ratio improves. :slight_smile:

Edit
I am sorry for my part in this thread going out of hand. But at least it is into AppleScript. I’ll just add that thinking over the compile process of the AppleScript compiler in a not so fine-granular way, the problem isn’t what is inside tell blocks, because it resolves terminlogy, and errors, if something is wrong. Right now, I more guess than think, that the problem is with any global variables that may, or may not be present at run time, that this dictates some ‘forgiveness’ by the compiler.

Anyways, I’ll of course politely answer any further things that addresses this topic. And ask StefanK, for forgiveness, if he found me to be rude or unappropriate earlier, but other than that, I really look forward to pick up the thread so to speak in code exchange, one day, maybe.

I just wanted finally to say that I really take pride in shipping things that works.

Apple has extended the posix regular expression in Mac OS X 10.8 with some extra functionalities, including wide character support :slight_smile:

edit: of course this extension is not according to the posix standard

That is precisely what I meant :cool:

Same to me, making a mistake doesn’t make you a bad programmer. It’s the same as your math teacher at college, you did get points to solve an equation if 9 out of 10 steps were done correctly. It’s much more important that the way you want to solve problem is correct than actually writing code without a typo. The latter will be working code without a warning while the first will just not run of have bugs that will show your problem sooner or later in the process of testing.

Always let the software be analysed by someone else, I never do it because it’s better to let it do by someone with a different mind set who haven’t actually wrote the code.

Keep doing that! Those rotten apples weren’t targeted to anyone here but just developers in general who share code or writing commercial software with the “if it compiles ship it” analogy. I like sharing code too, and I think it’s good. Especially when someone comes up with an better idea

They may not have fully used it before 10.8, but it was actually present among the libraries, in 10.6. At least I found it on my machine, after I had installed it by source from ICU. :slight_smile:

Actually, when it comes to regression testing, that is something I can do, at least when it comes to libraries. By having launchd trigger the file, based on modified date.
I can even tell the difference with files dropped into the library, and even though this means, I may be hamstrung, when I have to write the tests, it could improve code quality, the problem is of course, what happens with the handlers, after they have been tested, and then changed. Surmising they were tested initially. Retesting every case, consciously, and thoroughly is of course the way it should have been done. But sometimes one just looks it over, and overlooks something, that really should have been retested/correct. I see a personal room for improvement, regarding this! :slight_smile:

One problem with asking people to test things, is sheer consciousnes: is for fear of sucking the life blood out of them. It is one thing, if you know that the idea triggers them that they have use for, it is something totally different when the code addresses some problem, they couldn’t care less for. And we are all busy here.

Instead, I hope for, that if someone finds it useful, and finds a bug, that they then inform me of the problem, and even better, can tell me what the issue is., since I then can deal with it right away. I do that, when I get the geist, that the scripts are still supported. This has proven to be a non-reliable way of bug finding.

Though, some people here, like Nigel Garvey, StefanK, Yvan Koenig and probably others, have given feedback, when they have found bugs, and I am very grateful for that.

So, measuring my personal rooms for improvement, I really see one realistic option, and that is to manage to ‘do it right the first time’, and alleviate the need for someone else finding any errors, that should have been caught in the test-phase of a project. (There are things, like changing terminology, and capabilities, that you can’t do much with anyway. AppleScript is kind of a volatile environment, where things may change from one version of an app to the next.)

And the worst place to create an error is inside an on error block.

And the last thing, when there is an issue, is to post that there is an issue, and wait with posting the actual fix, until the fix is thoroughly tested.