I'd like to be able to switch the sound output source in Mac OS X without any GUI interaction.
There are tools to do control the sound output, such as SoundSource and an applescript to open the preferences dialog.
What I am looking for is something that switches the preference instantly, like SoundSource but it has to be scriptable. The goal is to switch between my digital and analog output with one keystroke. I have a helper application that will launch a program or applescript on one keypress. All I need now is the applescript or application that switches the sound source quickly without any user interaction.
I'm willing to write some Objective-C if that is what it takes, but I'm pretty much a newbie at Cocoa development.
Do you have a one-click solution or can point me to a good tutorial on controlling sound system preferences from a Cocoa App or command line?
EDIT: I created a command-line application to do exactly this. You may download it at http://code.google.com/p/switchaudio-osx/downloads. Source code is available on the project site as well.
I created a command-line application to do exactly this.
You may download it at http://code.google.com/p/switchaudio-osx/downloads. Source code is available on the project site as well.
UPDATE (Dec. 2014): the code is now hosted on github -- https://github.com/deweller/switchaudio-osx. And works just fine in Yosemite.
Don’t think of it in terms of preferences; there’s no centralized system preference framework for this sort of thing. I believe what you need to do is use Core Audio to set the kAudioHardwarePropertyDefaultOutputDevice and kAudioHardwarePropertyDefaultSystemOutputDevice properties of the AudioSystemObject (using AudioHardwareSetProperty()).
Related
I am trying to find the best way to handle application windows on Mac OS from a script. I am open to any language, but I want it to have the following capabilities
Get list of open applications
Get location of specific application
Change focus, position, and size of specific application
Send key events to only specific application
I have managed to get a list of applications using JNA, Apple's Core Graphics library, and some code from this question, but the capabilities seem to be limited. Is there a way to implement the functionality I am looking for, or is Mac OS too closed down for this? Like I said, I am open to all languages.
Thanks so much!
I've been looking around on the cplusplus forum and here on stackoverflow, but I have not been able to find an answer. All I find is Windows stuff or people working with IDE'S that do the work for them.
I am creating an application with c++ and GTKMM and nothing else, I just have a texteditor and a compiler that I control with my terminal (I adress this because a lot of people always talk about IDE'S and stuff) on UNIX based computers.
When I run my application (./application) I always see my terminal along with my gui application and I would like to hide the terminal. How would I achieve this?
Thanks in prior :)
So I found out it differs from operation system. I've written out what I've found on my website, so check it out if you want to create a mac application.
I'm automating excel with python through the COM interface, with pywin32. I'd like to port my script to mac. Is there any chance of this happening? I realize that I can't use COM on a mac, and the xlutils python modules won't work (since I need to copy graphs, etc.). Is there anything else I can use?
Unfortunately development of appscript has been stopped,
I'm not aware the development of AppleScript has been stopped. What is your source on that?
As far as I can tell, AppleScript is still maintained and has a future and is working well.
Also there is a distinction between "AppleScript" the scripting language and the Inter-Application Communication Technology (IAC) called: "AppleEvents"
You can find the AppleScript Editor.app at the following location on your Mac:
/Applications/Utilities/AppleScript Editor.app
Open up the AppleScript Editor.app and then choose from the File menu: "Open Dictionary..."
Then select "Excel.app"
This will open the Apple Event dictionary for Excel. You will be able to see "Nouns" and "Verbs" and "Properties" that are supported in Excel for Apple Events.
AppleScript can be used to send commands to Excel via Apple Events, but so can other scripting languages such as Python.
If I were you, I would consider making an abstract class of Excel and two concrete subclasses, one that uses the Windows version of the code for Windows and anther that uses the Apple Event code that the Mac version of Excel might need.
See: the Wikipedia Article on Apple Events:
http://en.wikipedia.org/wiki/Apple_events
It's really Apple Events -- not AppleScript that you may want to use, but you could look at the following article too:
See Also: the Wikipedia Article on AppleScript:
http://en.wikipedia.org/wiki/AppleScript
--- edit ---
I believe that the misconception that Apple is lessening its support of AppleScript comes from the fact that AppleScript Studio was discontinued, but it was replaced with something just as good or better. Now, you can use AppleScript to develop full-fledged Mac applications in XCode. In addition, AppleScript can also still be used in Automator workflows, in XCode to build Automator actions, and in the AppleScript Editor, all of which are delivered by Apple in the latest version of OS X (Mountain Lion 10.8.4) and in the latest version of XCode (version 4.6.2)
So AppleScript is still a viable option, though the OP was asking about a Python solution. Apple Events are available from Python.
Currently the only possible solution would be appscript, which is a module that allows to write AppleScript macros in python (and ruby). Unfortunately development of appscript has been stopped, but for now it keeps working well enough.
I developed a command line application, whose binary runs in Linux, Windows and Mac OSX. It reads some text input files, but I realize that some special users can not handle this. I would then like to build some kind of graphical interface, where the user only finds buttons and scroll bars for selecting the input parameters, a big "run" button, and then it reads the output of the program and makes some figures.
I also need that everything gets finally packed in a single file, which uses only static libraries, so the user just needs to copy the file to his/her machine and run it.
I would like to know what is the best open source and multi-platform approach to do this. 10 years ago I played a bit with something similar on DEC machines, so I guess that nowadays the situation has probably improved a bit.
P.S. For designing the graphical interface, I am looking for a graphical approach, where you add buttons, scroll bars with the mouse
P.S. 2: the interface is really simple, just need less than 10 buttons, 5 text fields and 2 scrolla bars
Thanks
For advanced UIs, I would generally recommend writing a different UI for each platform (since each platform has its human inteface guidelines). However, is this going to be a simple UI, then one of the cross-platform UIs.
You also didn't mention what language you want to use.
Lastly your "1 exe file" is a bit of a myth - it applies only to Windows. On MacOSX, we use the magic app folders, so it doesn't matter how many files comprise your app, you still get drag-n-drop installs.
Look into GTK+ which originated on Linux, or wxWidgets.
Tcl/Tk is a perfect choice. No other language provides as good of a deployment solution. You can create a virtual filesystem that has your application along with icons, sound files, etc into a single file for each platform (called a 'starpack'). You can even include binary executables and libraries, though those have to be copied to the actual filesystem at runtime to be used.
You also have the option of a two-file deployment -- a platform-specific runtime called 'tclkit', and a platform-independent application file called a 'starkit'. The one starkit will work on all platforms without recompiling, rebundling, etc. It can even have platform-specific parts built-inside and chosen at runtime.
A professional Tcl/Tk developer could do a front end to a command line program in a day without a graphical GUI design tool, easily. If you're new to tcl it will obviously take longer, but that is true of any language. The point being, Tk is remarkably easy to use and doesn't require a graphical GUI designer.
For a cross platform UI, you can use GTK (if using C) or QT (if using C++).
If you can live with a rather huge application package to deliver be sure to look at https://electronjs.org/ You can keep your functionality in your commandline apps and build a modern look and feel UI using HTML5 CSS JS and before thinking "this is ridiculous" consider that Microsoft's Visual Studio code is built on this and compared to GTK / wxWidgets you can do wonders with this. It isn't even hard to do but you either love it or hate it. I'm still undecided...
For a given extension, for example ".psd", I'd like to be able to determine the default application path for opening this file, for example "/Applications/Adobe Photoshop CS4.app".
I've looked into the Launch Services API, and there are clearly programmatic ways to get this information. Unfortunately for my particular scenario, only a scripting solution (Applescript or shell script) will do.
I've also looked at "lsregister -dump". It seems to be unwise to rely on parsing this information, since there are no guarantees as to the stability of the output format.
I've been solving this problem in the past with Creator Codes, but since Apple seems to be phasing them out since Snow Leopard I'm trying to eliminate dependence on Creator Codes.
thanks
Launch Services is the one and only place to get that information. You can write a scripting addition that will expose its functionality to AppleScript, but then you have to install that on whatever machine you plan to run on.
System Events does give you this in Leopard
alt text http://img.skitch.com/20091222-eessetxeqbai2mnwduygtm1cd5.png