0

I want to create a applescript menu file for a application, I need to edit that file so i have script in text file and i have edit the file and save it as a script file, but unfortunately its not detecting as script file by application "Outlook Mac 2011" and even when i open this file into script editor and try to save it's throwing error of unable to save so please help me on this

        userpath = [paths objectAtIndex:0];
        userpath = [userpath stringByAppendingString:@"/Microsoft User Data/Outlook Script Menu Items/"];
        userpath = [userpath stringByAppendingString:@"Create New Conference Event.scptd"];

        [[NSFileManager defaultManager] createFileAtPath:userpath contents:[content dataUsingEncoding:NSUTF8StringEncoding] attributes:nil];

        NSDictionary* errorDis = [[NSDictionary alloc] init];
        NSAppleScript *script = [[NSAppleScript alloc] initWithContentsOfURL: [NSURL fileURLWithPath:userpath] error:&errorDis];

then I am trying to compile the edited file

NSDictionary* errors = [NSDictionary dictionary];
        NSAppleScript* appleScript = [[NSAppleScript alloc] initWithContentsOfURL:url error:&errors];
        [appleScript compileAndReturnError:&errors];

I am getting this error

Printing description of errors:
{
    NSAppleScriptErrorNumber = "-43";
}
5
  • What is the content.? And also the extension for a Applescript Text file is ".applescript" Commented Dec 19, 2013 at 0:01
  • but the apple script witch use by outlook use has scpt extention Commented Dec 19, 2013 at 5:24
  • Yes. But you have .scptd which is for a bundle And the content is text. A Applescript text file may still work and would save you a lot of trouble trying to create a compiled file type Commented Dec 19, 2013 at 5:30
  • how can i create the compiled version because i am not able to read the content of scpt ext? Commented Dec 19, 2013 at 5:46
  • See my answer. I am not sure why you need the NSAppleScript ? but On my 10.9.x Mac I can open the file in Applescript and it is compiled. I used a simple 'say "hello"' Commented Dec 19, 2013 at 5:49

1 Answer 1

1

Assuming your 'Content' is a NSString.

Just change the scptd extension to scpt.

userpath = [userpath stringByAppendingString:@"Create New Conference Event.scpt"];

        [[NSFileManager defaultManager] createFileAtPath:userpath contents:[content dataUsingEncoding:NSUTF8StringEncoding] attributes:nil];

It seems that just doing this does save a compiled file that works when opened.

UPDATE*


An alternative is to run a script to store the outlook script using NSApplescript.

Example Code:

 NSString * scriptContent = @"say \"hello\"";
    NSString * scriptPath =@"\"/Users/USERNAME/Downloads/theScript.scpt\"";

    NSString * content =[NSString  stringWithFormat: @"set script_text to MakeScript()\n my RunMaker(script_text)\n on RunMaker(script_text)\n set file_spec to (%@) \n store script script_text in file_spec replacing yes \n end RunMaker \n on MakeScript() \n script \n  %@ \n end script \nend MakeScript",scriptPath,scriptContent];

    NSLog(@" content %@", content);

    NSDictionary* errorDis = [[NSDictionary alloc] init];
    NSAppleScript *script = [[NSAppleScript alloc] initWithSource:content];
    [script executeAndReturnError:&errorDis];

     NSLog(@" errorDis %@", errorDis);

The code compiles and runs as:

set script_text to MakeScript()
 my RunMaker(script_text)
 on RunMaker(script_text)
 set file_spec to ("/Users/USERNAME/Downloads/theScript.scpt") 
 store script script_text in file_spec replacing yes 
 end RunMaker 
 on MakeScript() 
 script 
  say "hello" 
 end script 
end MakeScript

Saving a script file named theScript.scpt in Downloads. ( From an existing applescript I had. it can be shortened )

Sign up to request clarification or add additional context in comments.

8 Comments

still its not detecting by outlook, it there any way to read and edit the applescript file? I mean compiled one
What Happens when you open it in Applescript Editor
its opening and i can execute it but outlook is not detecting it and if i try to save the file it's says unable to save
What happens if you change the extension to .applescript ( in the code)
file is creating but Outlook is not detecting, even I am able to run this edited script programatically but outlook not want to detect this edited file :(
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.