Saving Contents of OSAScriptView as a ".scpt" file into a predefined folder - objective-c

First, I'm totally new to Obj-C please go easy on me :D
I'm building an application, which basically does the same thing that AppleScript Editor does.
I have used an OSAScriptView, and what I would like to do is to save the contents of this OSAScriptView as a .scpt file in a predefined folder. (like /documents/myscripts/newscript.scpt)
Thanks in advance!

The class OSAScript contains the method you are looking for.
#interface OSAScript : NSObject
// Instance Members
- (BOOL)compileAndReturnError:(NSDictionary**)errorInfo;
- (BOOL)isCompiled;
- (BOOL)writeToURL:(NSURL*)url ofType:(NSString*)type error:(NSDictionary**)errorInfo;
- (BOOL)writeToURL:(NSURL*)url ofType:(NSString*)type usingStorageOptions:(OSAStorageOptions)storageOptions error:(NSDictionary**)errorInfo;
- (NSAppleEventDescriptor*)executeAndReturnDisplayValue:(NSAttributedString**)displayValue error:(NSDictionary**)errorInfo;
- (NSAppleEventDescriptor*)executeAndReturnError:(NSDictionary**)errorInfo;
- (NSAppleEventDescriptor*)executeAppleEvent:(NSAppleEventDescriptor*)event error:(NSDictionary**)errorInfo;
- (NSAppleEventDescriptor*)executeHandlerWithName:(NSString*)name arguments:(NSArray*)arguments error:(NSDictionary**)errorInfo;
- (NSAttributedString*)richTextFromDescriptor:(NSAppleEventDescriptor*)descriptor;
- (NSAttributedString*)richTextSource;
- (NSData*)compiledDataForType:(NSString*)type usingStorageOptions:(OSAStorageOptions)storageOptions error:(NSDictionary**)errorInfo;
- (NSString*)source;
- (NSURL*)url;
- (OSALanguage*)language;
- (id)initWithCompiledData:(NSData*)data error:(NSDictionary**)errorInfo;
- (id)initWithContentsOfURL:(NSURL*)url error:(NSDictionary**)errorInfo;
- (id)initWithContentsOfURL:(NSURL*)url language:(OSALanguage*)language error:(NSDictionary**)errorInfo;
- (id)initWithSource:(NSString*)source language:(OSALanguage*)language;
- (id)initWithSource:(NSString*)source;
- (void)setLanguage:(OSALanguage*)language;
You can create it yourself, or use the class OSAScriptController, which will create one automatically.

Related

How to find deep nested realm objects based on property of a higher parent?

Here is a schema example
ModelA:
- List<ModelB>
ModelB:
- id
- ModelC
ModelC:
- ModelD
ModelD:
- interes_prop
I want interes_prop from ModelD based on id of ModelB.
I tried to use linkingObjects but I don't always know the nesting level.
realm.objects(ModelD) gives me resuts from different ModelBs which is not what I expect.

Swap values within classes

How can I swap values within classes please?
As shown in this table:
- - - - - - - - - - Before - - - - - - - - - - - - - - - - - - After - - - - - - - - - -
I want to do this because it is over sampled data. It is very repetitive and this causes machine learning tools to over fit.
OK, try this out:
# Setup example dataframe
df = pd.DataFrame({"Class" : [1,2,1,3,1,2,1,3,1,2,1,3,1,2,1,3],
1:[1,1,1,0,1,0,1,0,1,0,1,0,1,0,1,1],
2:[0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0],
3:[0,0,1,1,1,0,1,1,0,0,1,1,1,0,1,1],
4:[1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1],
5:[0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1],
6:[0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1]}).set_index("Class")
# Do a filter on class, and store the positions/index of matching contents
class_to_edit=3
swappable_indices = np.where(df.index==class_to_edit)[0]
# Extract the column to edit
column_to_edit=1
column_values = df[column_to_edit].values
# Decide how many values to swap, and randomly assign swaps
# No guarantee here that the swaps will not contain the same values i.e. you could
# end up swapping 1's for 1's and 0's for 0's here - it's entirely random.
number_of_swaps = 2
swap_pairs = np.random.choice(swappable_indices,number_of_swaps*2, replace=False)
# Using the swap pairs, build a map of substitutions,
# starting with a vanilla no-swap map, then updating it with the generated swaps
swap_map={e:e for e in range(0,len(column_values))}
swap_map.update({swappable_indices[e]:swappable_indices[e+1] for e in range(0,len(swap_pairs),2)})
swap_map.update({swappable_indices[e+1]:swappable_indices[e] for e in range(0,len(swap_pairs),2)})
# Having built the swap-map, apply it to the data in the column,
column_values=[column_values[swap_map[e]] for e,v in enumerate(column_values)]
# and then plug the column back into the dataframe
df[column_to_edit]=column_values
It's a bit grubby, and I'm sure there's a cleaner way to build that substitution map in perhaps a one-line list comprehension - but that should do the trick.
Alternately, there's the np.permute function which might bear some fruit in terms of adding some noise (albeit not by performing discrete swaps).
[edit] For testing, try a dataset with a bit less rigidity, here's an example of a more randomly generated one. Just edit out the columns you want to replace with fixed values if you want to impose some order in the dataset.
df = pd.DataFrame({"Class" : [1,2,1,3,1,2,1,3,1,2,1,3,1,2,1,3],
1:np.random.choice([0,1],16),
2:np.random.choice([0,1],16),
3:np.random.choice([0,1],16),
4:np.random.choice([0,1],16),
5:np.random.choice([0,1],16),
6:np.random.choice([0,1],16)}).set_index("Class")

How to get a YAML flowchart in a pdf

So i run a minecraft server using spigot. If you are familure with the game it is written in java and has a YML file. Anyways i remember something like this done way in the past where you could have a script run and it has a flowchat of permissions that inherit each other like it just has all of the permissions in a nice looking Flowchat. I have tried searching if something like this existed but i couldn't find anything and i am wondering if something like that is out there that i can use to make a easy to view PDF with all of the permissions. I am going to include a sample of the permission fike to show the format.
Moderator:
options:
prefix: '&f[&aMod&f] '
rank: '400'
inheritance:
- Member
permissions:
- essentials.clearinventory
- essentials.invsee
- essentials.kick
- essentials.mute
- essentials.tempban
- essentials.fly
- essentials.speed
- essentials.jump
- essentials.ban.notify
- essentials.mute.notify
- essentials.kick.notify
- essentials.enderchest
- essentials.top
- coreprotect.inspect
- nocheatplus.notify
- bm.notify.*
- nocheatplus.checks
- bm.command.tempban
- bm.command.warn
- bm.command.warn.offline
- bm.command.mute
- bm.command.bminfo.*
This is the format for all of the file. Where it says inheritance thats basily there are perms for a rank below that this rank inherits

Heirachical grid group by features and userstotries ,subuserstories and task

I have rally data in which userstories is associated with features.
I want to show heirarchical features and usetstories ,subuserstories and tasks up to n level. Is it possible to do ?
eg.
feature1
- userstory 1 - subuserstory1 -
- subsubuserstory1 - task
- task
- subsubuserstory1 - task
subuserstory2-
- subsubuserstory3 - task
- subsubuserstory4 - task
userstory 2
- subuserstory 3
- subsubuserstory5
- subsubuserstory6
userstory 3
-subuserstory 4
- subsubuserstory7
- subsubuserstory8
Also i want to show Testcase count for each userstory/substory in rally app .
See Rally.ui.grid.TreeGrid.
There is a full example of a tree grid that starts on PI/Feature level and includes associated stories and tasks here.

Circular Definitions in yaml

I'm trying to use yaml to represent a train network with stations and lines; a minimum working example might be 3 stations, connected linearly, so A<->B<->C. I represent the three stations as follows:
---
stations:
- A
- B
- C
Now I want to store the different lines on the network, and where they start/end. To do this, I add a lines array and some anchors, as follows:
---
stations:
- &S-A A
- &S-B B
- &S-C C
lines:
- &L-A2C A to C:
from: *S-A
to: *S-C
- &L-C2A C to A:
from: *S-C
to: *S-A
and here's the part I'm having trouble with: I want to store the next stop each line at each station. Ideally something like this:
---
stations:
- &S-A A:
next:
- *L-A2C: *S-B
- &S-B B:
next:
- *L-A2C: *S-C
- *L-C2A: *S-A
- &S-C C:
next:
- *L-C2A: *S-B
(the lines array remains the same)
But this fails - at least in the Python yaml library, saying yaml.composer.ComposerError: found undefined alias 'L-A2C'. I know why this is - it's because I haven't defined the line yet. But I can't define the lines first, because they depend on the stations, but now the stations depend on the lines.
Is there a better way to implement this?
Congradulations! You found an issue in most (if not all) YAML implementations. I recently discovered this limitation too and I am investigating how to work around (in Ruby world). But that's not going to help you. What you are going to have to do is store the "next stops" as a separate set of data points.
next-stops:
*S-A:
- *L-A2C: *S-B
*S-B:
- *L-A2C: *S-C
- *L-C2A: *S-A
*S-C:
- *L-C2A: *S-B
Does that help?