Page 1 of 1

AppleScript wrapper

Posted: Sat Jan 16, 2010 8:04 am
by wilbert
I'm trying to learn a bit about Objective-C / Cocoa.
As an experiment I wrapped NSAppleScript in a very simple way.

It's only one command

Code: Select all

COCOA_AppleScript("beep 3")
Debug COCOA_AppleScript("tell application " + Chr(34) + "Finder" + Chr(34) + " to get the name of every item in the desktop")
I tried to create the userlib both OSX x86 and ppc (ASCII and Unicode) and included both in the zip archive but since I don't have a ppc based system I wasn't able to test it.
Link to userlib : http://www.w73.nl/pb/libPBCocoa.zip

Re: AppleScript wrapper

Posted: Mon May 02, 2011 12:56 pm
by jesperbrannmark
I am really trying to make this work, I have the userlibs in my purebasic userlibs directory as default - but I am getting "is not a function".... Any suggestions?
With Applescript we could solve several of the issues I've posted here like; open webpage in safari to print, use webcam, scan etc.

Re: AppleScript wrapper

Posted: Mon May 02, 2011 1:06 pm
by jesperbrannmark
should probably mention i am using PB 4.60 b2...

Re: AppleScript wrapper

Posted: Mon May 02, 2011 1:55 pm
by wilbert
Are you sure you put the libs in the right directory ?
It works fine when I try it in PB 4.60 b2 .

Re: AppleScript wrapper

Posted: Mon May 02, 2011 4:58 pm
by jesperbrannmark
What is the right directory? I have all the libs included in purebasic in applications/purebasic/beta460/purelibraries including this one, should it be in any other directory? (i just tried saving my sourcefile in same directory but it doesnt change)
Do i need to do any kind of includebinary, includefile or anything?

Re: AppleScript wrapper

Posted: Mon May 02, 2011 5:25 pm
by wilbert
Inside the purelibraries directory is a subdirectory userlibraries .
Inside that subdirectory is where you have to put it.
You don't have to include anything. It should work.
You could try the 'Restart Compiler' option but normally that shouldn't be required.

Re: AppleScript wrapper

Posted: Mon May 02, 2011 5:40 pm
by jesperbrannmark
Wow :D :D :D
Thanks a lot.
Its working great. I will try to smash together some Applescript solutions to things and post it over the comming days!

Re: AppleScript wrapper

Posted: Fri May 06, 2011 11:22 am
by jesperbrannmark
I now use the wrapper for several things. Its awsome and open up a new world of functions, including webcam - recording - photos etc etc. I will post some examples.

I see a difference, I dont know why.

For example I have the following line:
COCOA_AppleScript("tell application "+Chr(34)+"Safari"+Chr(34)+Chr(13)+Chr(10)+"make new document at end of documents"+Chr(13)+Chr(10)+"set url of document 1 to "+Chr(34)+url.s+Chr(34)+Chr(13)+Chr(10)+"end tell")

Works fine.
Compile
Still works.
Move program to USB stick - doesnt work any more
Move program to another computer - doesnt work.

Is there any file I need to keep along with my program?

Re: AppleScript wrapper

Posted: Fri May 06, 2011 12:28 pm
by wilbert
I see no reason why it shouldn't work from a usb stick.

Re: AppleScript wrapper

Posted: Tue Jun 21, 2016 10:27 pm
by rootuid
fast forward a couple of years :)
I'm running Mac Os X 10.11.5 El Captain.I placed libPBCocoa_x86 in PureBasic / PureLibraries / UserLibraries/ folder
When I attempt to run

Code: Select all

COCOA_AppleScript("say "+Chr(34)+"Purebasic applescript rules"+Chr(34)+" using "+Chr(34)+"cellos"+Chr(34))
I get

Code: Select all

...is not a function (or not available in the demo version) etc....
Any one want to give it a go? I tried restarting the PB compiler but same error :(
Thanks.

Re: AppleScript wrapper

Posted: Wed Jun 22, 2016 5:34 am
by Danilo
No lib required: Calling AppleScript