Applescript "random number" keyword breaks after importing foundation - applescript

I have a random number generator in applescript that works fine until I import foundation for another section of code.
use framework "Foundation"
set myNumber to (random number from 0 to 65535) as integer

because once you use "use framework", the script is gonna forget to use default applescript commands so to fix this, simply add:
use scripting additions
eg.
use framework "Foundation"
use scripting additions
set myNumber to (random number from 0 to 65535) as integer
this will tell the script that it can use the frameworks as long as it still uses default applescript commands
Hope this helped :D

Related

How to get NSImage.Name in AppleScriptObj

How to get NSImage.Name.cautionName
in AppleScriptObj.
I tried:
set cautionName to aN of NSImage.Name
but that does not work.
It looks like what you are after is NSImageNameCaution, which is a constant for the name of a system image. Your example (and link) appear to be using Swift, changing the documentation language to Objective-C gives you the proper term.
AppleScriptObjC uses names from the Objective-C documentation (it also does not use dot notation), so it would be something like:
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "AppKit"
use scripting additions
# get the name
set imageName to (current application's NSImageNameCaution) as text
# get the image
set theImage to current application's NSImage's imageNamed:(current application's NSImageNameCaution)
It needs pipes to indicate that it is method
set cautionName to (anImage's |name|()) as text
NOTE: if the Image has not the associated name, then of course you will get missing value.

Is there functionality to generate a random character in NSIS

I need to generate a random character during an NSIS installer script multiple times.
Is there a pre-defined function or is it even possible?
If yes: How?
There is no predefined function but the wiki has plugins and basic (non-crypto) pure NSIS random functions to choose from:
http://nsis.sourceforge.net/Rnd
http://nsis.sourceforge.net/Random
http://nsis.sourceforge.net/Pwgen_plug-in
http://nsis.sourceforge.net/NsRandom_plug-in
http://nsis.sourceforge.net/Generate_a_random_number

Scripting itunes without applescript?

I am looking for a way of scripting iTunes using something else then AppleScript. I want to mass-manipulate the title-name and artist of tracks. Using some id3-tool won't help, because as far as I know the iTunes database will not update, if I don't use iTunes for manipulating this information. As I don't know how to code with AppleScript and don't really have the time to dive into this, I wonder: is there any way to do this task using javascript, lua, bash or php?
thanks,
I suggest you to learn AppleScript, at least for a day. The point is, the inter-GUI-app communication in OS X is done via Apple Events, whose construct follows that of its main language AppleScript. There are many bridges which allow you to call Apple Events from various languages, but you need to understand the concept of Apple Events first. So, at least you need a bit of familiarity with AppleScript.
This is just as in the case of Cocoa: you can code Cocoa apps in many languages, but most of the documentation and the concept are based on Objective-C. So you need to at least a bit of familiarity with Objective-C before coding Cocoa in other languages.
So, let me give you a very very short overview of Apple Events/ AppleScript system.
Each app implements an object-oriented system and exposes it to the outside world as a dictionary, which you can read with AppleScript Editor. Open the AppleScript Editor, and choose File → Open Dictionary, and choose iTunes. There, you see the list of commands, classes, methods in those classes, etc. Then, from AppleScript or Ruby or Lua, you access these objects and methods.
Suppose you want to rename the selected entries of iTunes from "A-B" to "B-A". Then the code would be
set text item delimiters to "-"
tell application "iTunes" -- following statements are targeted to iTunes
repeat with entry in selection -- "selection" is a concept implemented in iTunes
set s to name of entry -- copy the name of entry to a local string s
set x to text items of s -- split the string s to a list according to text item delimiters
set y to {item 2 of x, item 1 of x} -- construct another list
set name of entry to y as string -- set the name. Note that "as string" adds the delimiters
end repeat
end tell
Yes the grammar of AppleScript is a bit weird, but it basically has one-to-one correspondence with a regular imperative language. Just refer to the official language guide if you're confused. And text operations in AppleScript without a good OSAX (AppleScript's extension system) is a chore. So I agree it's not a bad idea to first get familiar with the concept of AppleScript, and then use it from Ruby or any of your favorite languages.
But remember, open the dictionary in AppleScript editor, because that's where you find what each app implements and exposes to the system!
You can send Apple Events from JavaScript with JavaScriptOSA. However I'd recommend you investigate appscript (Python, Ruby) instead as it's more up-to-date and supported.

Translate Applescrip [key code 125 using command down] to appscript

how to translate the following Applescript to appscript:
tell application "System Events"
key code 0 using command down
end tell
I want to perform "Command + A"-like short cut, i.e., select all texts.
Look at the application ASTranslate which was installed as part of Appscript. It translates Applescript to Appscript for Python or Ruby. Be aware it just traps Apple Events and thus won't translate Applescript structures like loops or the like. It's very easy to use. Just past your Applescript in one pane, hit cmd-R, and it'll generate the translated Appscript + Python code. For your example it is
app(u'System Events').key_code(0, using=k.command_down)
While occasionally you'll find something that won't work quite right in general ASTranslate is an essential tool for using Appscript.
Bellow is the usage of keystroke of Applescript via Python, which is hard to search:
http://www.agapow.net/programming/python/applescript-via-python

Debugging a Scheme program

I am using Festival, a text-to-speech synthesizer, for a project. It has a Scheme scripting language. I'm very new to scheme and hope someone can help. I just want to see the current configuration parameters of Festival. I have a Scheme prompt and can change existing parameters with the following commands:
festival> (Parameter.set 'Horse 3)
3
festival> (Parameter.get 'Horse)
3
Now, I'd like to see every parameter at once, instead of just one at a time. Is there a simple Scheme command to do this?
Look at how Parameter is internally represented. If it is an association list, you can just print it. You can also try these free Scheme debuggers:
Schemeide
Psd

Resources