This may be more suited in the ObjC forum category, but here is my problem. I had a working applescript application where the main.scpt runs fine. I also had a cocoa-applescript application that works fine on its own and I wanted to use it with my applescript app, so I put my applescript main.scpt into the scripts folder of the cocoa one and renamed the cocoa main.scpt which is called later in the applescript script. Here is the new main.scpt (that is taken from an applescript main.scpt)
set {button returned:mediaType} to (display dialog "Please select which type of media you are trying to make:" buttons {"TV Show", "Movie", "Cancel"})
if mediaType is equal to "TV Show" then
tvShow()
else if mediaType is equal to "Movie" then
movie()
end if
do shell script ("afplay /System/Library/Sounds/Glass.aiff")
on movie()
tell application "Finder" to set movieScpt to load script file ((path to me as text) & "Contents:Resources:Scripts:movie.scpt")
run movieScpt
end movie
on tvShow()
tell application "Finder" to set fileworkScpt to load script file ((path to me as text) & "Contents:Resources:Scripts:filework.scpt")
run fileworkScpt
end tvShow
The problem is, I keep getting an error that it can’t make <> into type constant. I am assuming it has something to do with the loading/running other script files, and maybe that doesn’t play nice in the cocoa-applescript part. But this exact script in my just applescript app works fine. Let me know what you guys think. Thanks.
You can’t do that. The shell applications that run them are quite different. (And those references to the Finder in your script are unnecessary.)
Thanks for letting me know what was the problem. Any idea on how to go about fixing this?
It’s not clear what you want to do. It sounds like you just need to edit the Cocoa-AppleScript application.
So put the original cocoa applescript main.scpt back where it is supposed to be and rename it back to main.scpt. Then call all the other scripts from there?
That may well work, but be prepared for complications. Once you load your other scripts into a Cocoa-AS script, they too run as Cocoa-AS, and there are some quirks involving Cocoa-AS scripts.
Damn alright. Are there any other options? Somehow get all the other scripts to strictly run as applescript?
it’s impossible to answer without having some idea of what they do.
There are five more scripts total. They range from renaming files, sorting through folders, pulling zip files and xml files from websites, unzipping. Some shell scripts. The end all is that it gets the name of a folder that is the name of a tv series, searches the series in a database, you use the cocoa-applescript guy to select which series you want, then it pulls all the episode names from the online database and renames all the movie files with the correct name and season/episode number.
What version of the OS does it need to run under?
Well I am on 10.10 right now.
Then one possibility is to put the stuff in the Cocoa-AS app in an ASObjC-based library instead. That way you can easily load it from other apps.
The key is you generally want to run handlers from loaded scripts, rather than telling loaded scripts to run.
Alright so instead of putting it into a library could I instead enclose each script into their own handlers and then load and call those instead?
Sort of, depending on the scripts. It may be that they already have handlers you can call.
Sorry to keep sounding vague, but it depends a lot on how the scripts were written.
I never wrote a handler for any of them. So I will go back into each and enclose the entire script in a handler, call those instead of running the scripts and see if that works.