AppleScript wrapper

Mac OSX specific forum
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

AppleScript wrapper

Post 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
Last edited by wilbert on Wed May 31, 2017 3:14 pm, edited 1 time in total.
jesperbrannmark
Enthusiast
Enthusiast
Posts: 536
Joined: Mon Feb 16, 2009 10:42 am
Location: sweden
Contact:

Re: AppleScript wrapper

Post 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.
jesperbrannmark
Enthusiast
Enthusiast
Posts: 536
Joined: Mon Feb 16, 2009 10:42 am
Location: sweden
Contact:

Re: AppleScript wrapper

Post by jesperbrannmark »

should probably mention i am using PB 4.60 b2...
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: AppleScript wrapper

Post 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 .
jesperbrannmark
Enthusiast
Enthusiast
Posts: 536
Joined: Mon Feb 16, 2009 10:42 am
Location: sweden
Contact:

Re: AppleScript wrapper

Post 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?
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: AppleScript wrapper

Post 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.
jesperbrannmark
Enthusiast
Enthusiast
Posts: 536
Joined: Mon Feb 16, 2009 10:42 am
Location: sweden
Contact:

Re: AppleScript wrapper

Post 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!
jesperbrannmark
Enthusiast
Enthusiast
Posts: 536
Joined: Mon Feb 16, 2009 10:42 am
Location: sweden
Contact:

Re: AppleScript wrapper

Post 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?
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: AppleScript wrapper

Post by wilbert »

I see no reason why it shouldn't work from a usb stick.
rootuid
User
User
Posts: 35
Joined: Sat Nov 23, 2013 11:46 am

Re: AppleScript wrapper

Post 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.
User avatar
Danilo
Addict
Addict
Posts: 3037
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: AppleScript wrapper

Post by Danilo »

No lib required: Calling AppleScript
Post Reply