Comments (15)
Oof, returning objc collections is not something I've run into much yet. There's a design issue here as well as a technical one. I think what we'd want to do will depend on the type it would normally return in objc ... if it's a simple iterable we can maybe build a slice, which would involve using objc methods to iterate and build the slice. The exception being if it's a mutable collection and its part of the intended use of the API (since changing a built slice in Go won't reflect in objc). Or if the iterable class has other domain specific methods, it would make more sense to wrap in a Go type for the iterable objc class. This would mean you'd have to interact with it using methods, not Go slice/array mechanisms.
So looking at the API they're using NSArray, which is for "static" arrays, so I'd say it would make sense to iterate over the array and build a Go slice of NSRunningApplication objects.
from macdriver.
Thanks for the info. Using NSArray and iteration is working for me so far.
I haven't got my head around objc yet. Do you have an example of how i could get the type returned instead of just assuming its an NSArray.
from macdriver.
You can usually get an object type with the class
method of any object:
https://developer.apple.com/documentation/objectivec/1418956-nsobject/1571949-class
But obviously docs are where I start.
from macdriver.
@AStrangwood What is the main method of that function? Is there a delegate being set? is there an app.Send("run") anywhere?
from macdriver.
@asad-awadia what are you trying to accomplish?
from macdriver.
@progrium I am trying to get the application that is currently in focus/active
func main() {
delegate := objc.Get("NSWorkspace").Alloc().Init()
app := delegate.Send("sharedWorkspace") //.Send("activeApplication")
app.Set("delegate:", delegate)
fmt.Println(app)
}
this is my code atm and it returns nil
from macdriver.
The below works for me. Although the docs say "activeApplication " is depreciated and to use "runningApplications" which is what i have been doing in my code.
var NSWorkspace_ = NSWorkspace{objc.Get("NSWorkspace")}
type NSWorkspace struct {
objc.Object
}
func NSWorkspaceShared() NSWorkspace {
return NSWorkspace{NSWorkspace_.Send("sharedWorkspace")}
}
func (ws NSWorkspace) ActiveApplication() core.NSDictionary {
return core.NSDictionary{ws.Send("activeApplication")}
}
func main(){
workspace := NSWorkspaceShared()
app := workspace.ActiveApplication()
}
from macdriver.
shit it works!
thank you so much!
from macdriver.
how do you know when to use get, send, allc/init??
from macdriver.
func main() {
app := objc.Get("NSWorkspace").Send("sharedWorkspace").Send("activeApplication")
fmt.Println(app)
}
why does this not work? It is the same thing just without the wrapper structs no?
from macdriver.
how do you even read the values from the returned thing in your above example? :S
from macdriver.
func main() { app := objc.Get("NSWorkspace").Send("sharedWorkspace").Send("activeApplication") fmt.Println(app) }
why does this not work? It is the same thing just without the wrapper structs no?
Tried the code and it worked for me.
how do you know when to use get, send, allc/init??
The best answer to this is do some reading up on Objective-C
get,send will both work in the say way in the above cases. The difference is send allows you to pass on variables to the method you are calling. https://github.com/progrium/macdriver/blob/main/objc/object.go#L121
how do you know when to use get, send, allc/init??
allow/init are used to create a new instance/object of a class.
how do you even read the values from the returned thing in your above example? :S
You will need to implement the methods in NSDictionary first then you can use them.
https://developer.apple.com/documentation/foundation/nsdictionary?language=objc
from macdriver.
can somebody clarify if we can close this or what the next actionable thing is?
from macdriver.
@progrium it is closed from my end
but the project needs some more documentation
from macdriver.
was there something specific in mind or is that a general musing? i also think the project needs some more documentation, but that's not really a step forward.
from macdriver.
Related Issues (20)
- Framework Request: CryptoKit
- Related project: c_ocoa HOT 2
- Are there any plans to add Keychain Service?
- SetDefaultApplicationAtURLToOpenContentTypeCompletionHandler error
- ComboBox `SetDelegate` uses `TextField`'s `SetDelegte` resulting in error HOT 1
- module github.com/progrium/macdriver@latest found (v0.4.0), but does not contain package github.com/progrium/macdriver/keycode HOT 2
- Can I use Network Extension HOT 2
- Framework Request: ScreenCaptureKit
- DarwinKit: Rendering Problem with OutlineView
- SetDuration Can not set duration for amination
- Nib's InstantiateWithOwnerTopLevelObjects() not returning objects HOT 9
- Generator change: keep Objective-C type when parameter is a pointer to a pointer HOT 1
- Framework Request: StoreKit HOT 2
- enumexport error with call to s.Parse
- Generating appkit problem with enumtypes.gen.go and aliastypes.gen.go
- APFS (Case-sensitive) filesystem protocols.gen.m:3:9: fatal error:: 'Appkit/Appkit.h' file not found
- Can macdriver be used to implement macOS widgets and install them directly into the macOS notification center or desktop?
- corelocation API giving panic HOT 6
- Dictionary's DictionaryWithObjectsAndKeys() throws NSInvalidArgumentException HOT 6
- An error occurs when running the layout example. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from macdriver.