How to play the macOS "Trash" system sound? - cocoa

I found several macOS system sounds inside
/System/Library/Components/CoreAudio.component/Contents/SharedSupport/SystemSounds
including the trash sound when you delete a file in finder in dock/drag to trash.aif.
However I could not find an API to play any of these sounds. I would really prefer not to hardcode any file paths.
PS: An option would probably be to simply copy the sound to my own app bundle, but I also want to avoid that if possible (also licensing?).

Import AudioToolbox framework and use AudioServicesPlaySystemSound function. The argument values are not documented and are subject to change the same as the hard coded paths. It should pass the app store review as it's not private API.
//drag to trash.aif
AudioServicesPlaySystemSound(0x10);
//poof item of dock.aif
AudioServicesPlaySystemSound(0xf);
The only documented values are:
CF_ENUM(SystemSoundID)
{
kSystemSoundID_UserPreferredAlert = 0x00001000,
kSystemSoundID_FlashScreen = 0x00000FFE,
// this has been renamed to be consistent
kUserPreferredAlert = kSystemSoundID_UserPreferredAlert
};
Here is list of undocumented values
1 "Volume Mount.aif"
2 "Volume Unmount.aif"
3 "Media Keys.aif"
4 "Sticky Keys ON.aif"
5 "Sticky Keys OFF.aif"
6 "Sticky Keys MODIFER.aif"
7 "Sticky Keys Locked.aif"
8 "Sticky Keys Stuck.aif"
9 "Mouse Keys ON.aif"
10 "Mouse Keys OFF.aif"
11 "Slow Keys, 1st Key Pressed.aif"
12 "Slow Keys, Key Registered.aif"
13 "empty trash.aif"
14 "move to trash.aif"
15 "poof item off dock.aif"
16 "drag to trash.aif"
17 "InkSoundBecomeMouse.aif"
18 "InkSoundStroke1.aif"
19 "InkSoundStroke2.aif"
20 "InkSoundStroke3.aif"
21 "InkSoundStroke4.aif"
22 "burn complete.aif"
23 "burn failed.aif"
24 "Grab.aif"

Related

Why does OSX and Windows import my .pfx file differently?

I've got a .pfx file I can't share (work-related), but when I load it up on Windows my public key starts with 30 82 01 0a ... (truncated, see screenshot)
Windows screenshot
And when I load it up with on macOS it begins with BF:CF:10...
macOS screenshot
Even though it is the same file, the serial number of the loaded certificate and the public key seem to differ, which is causing problems for my C# Unity project when I try to connect to it. They have the same Authority Key Identifier, Subject Key Identifier, and Thumbprint, but differ in their Serial Number (4274337a15ab78c4 for Windows, and 4788598903244265668 and public key).
Is there a reason why Windows and macOS would differ in the details when loading the same certificate file?
It looks like they are importing it the same, just displaying it differently. The difference in serial numbers is due to Windows showing it in hex, and macOS in decimal.
The public key is a bit more complicated, but look closely at the top line of the Windows display. It starts with "30 82 01 0a 02 82 01 01 00", but the bytes following that, "bf cf 10 be e7 b1 1d af ..." match with the first bytes of what macOS lists as the public key.
I don't have a Windows system to look at, but I think what's happening is that the "Public Key" it shows is actually an ASN.1 data structure containing the modulus and exponent that make up the public key. macOS, on the other hand, lists the modulus (labeled "Public Key") and exponent separately, and doesn't bother with the surrounding ASN.1 headers (the "30 82 ..." stuff).

Applescript Press and hold ⌘ F2 for 5 seconds?

I'm basically trying to figure this out because I want to use my iMac as an external monitor for my macbook air. I also want to use the iMac keyboard for my macbook air however for some reason, Apple has decided that once you press and hold Command F2 to activate Target Display Mode (meaning it is now an external monitor) that the keyboard paired with the iMac cannot be unpaired with the iMac.
To work around this I thought I would just pair the keyboard with the macbook air initially (leaving the iMac without a keyboard) and create an Applescript macro that would simulate the keyboard pressing and holding the Command F2 for five seconds eliminating the need to go buy another Apple keyboard.
Here's what I have so far and it doesn't work. It's telling me F2 is not right. I'm pretty sure F2's key code is 120.
tell application "System Events"
key down Command
key down F2
delay 5
key up Command
key up F2
end tell
Does anyone know how I might accomplish this?
Observations as of OS X 10.9.1:
There's a problem with the way you're sending F2 (you need to use (key code 120) instead of just 120), but the larger problem is that key up/down only works as expected with modifier keys.
While NON-modifier keys can be sent (using (key code <n>) syntax), the up / down aspect is ignored, making both key down (key code <n>) and key up (key code <n>) statements effectively the same as key code <n> (i.e., a Key Down event immediately followed by a Key Up event is sent).
There's a suggested workaround here, based on repeatedly sending keystrokes in short sequence - it's worth a try, but from a technical perspective it's not the same as keeping a key [combination] held down, so I'm not sure it'll work.
Adapted to your situation (and replacing key down with key code), we get:
tell application "System Events"
set now to the seconds of the (current date)
set later to now + 5
if later > 60 then set later to later - 60
key down command
# Workaround: send F2 repeatedly.
repeat while the seconds of the (current date) is not later
key code 120
end repeat
key up command
end tell
As I said: this may not work; also note that the loop is "tight" meaning that it'll make your machine pretty busy (if sending keys repeatedly, but not necessarily as fast as possible is an option, you could insert a short delay).
Some optional background info:
The key up and key down commands, while also requiring the System Events context, are NOT exposed in the System Events.sdef, the app's dictionary (only key code and keystroke are listed) - this may indicate that Apple doesn't officially support them.
On OS X 10.9.1 (unlike on OS X 10.8 - don't know about earlier versions) there is a bizarre bug where an extra "a" keypress is sent whenever you use key down with a (keycode <n>) specifier.
Ways of determining key-code values (gleaned from various other SO answers, mostly here):
Key Codes, a free GUI app for interactive use - very handy.
The following header file on your system (list of codes in hex format):
/System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/HIToolbox.framework/Versions/A/Headers/Events.h
List of decimal codes (incomplete):
I've started a project to do something similar, namely monitor the iMac and automatically trigger target display mode and toggle off bluetooth when a Macbook is connected. You can download it from https://github.com/duanefields/VirtualKVM.

How to get CPF file to QL420/QL220

I have to provision over 30 QL420plus printers and I'm struggling with what I thought would be easy..
We are going to use the printers in conjunction with an in-house app we have written on Windows Mobile 6. Basically the app sends a stream to of CPCL commands to print a label. As the label has non-standard fonts we have created 7 CPF files that we need to put on the printer.
However the problem is that the new version of LabelVista (now called Zebra Designer v2.2.3) will not let you "Send a Font" like you could in the LabelVista that ran on Windows XP. You have to use the "Zebra Font Downloader". This is where the problem really comes home because it will not let you add a CPF file. You have to create a MMF file and then download it to the printer. This creates one big file which has the various fonts in it. This is pretty useless when the label format looks like this:
! 0 200 200 304 {8}
LABEL
CONTRAST 0
TONE 0
SPEED 3
PAGE-WIDTH 408
BAR-SENSE 50
COUNTRY UK
VT 7 0 280 220 {0}
VB EAN{13} 1 2 60 310 230 {9}
T Got08Bpt.cpf 0 5 3 {1}
T Got05Bpt.cpf 0 5 91 TICKET PRICE
T Got010Bpt.cpf 0 5 220 RETAIL PRICE
T Got012Bpt.cpf 0 5 240 {12}
T Got014Bpt.cpf 0 20 240 {6}
CONCAT 5 105
Got28Bpt.cpf 0 0 {10}
Got14Bpt.cpf 0 7 {11}
ENDCONCAT
FORM
PRINT
I need different font sizes for each text line written on the label, yet I can't download the CPF files individually to the printer.
I can't install the old verison of LabelVista becuase it won't let me install on Windows 7. I have read the CPCL Progrmaming guide from Zebra and that's ot helpful at all. Can anyone help or my Zebra account manager is going to have a really bad day. :-)
Thanks
Mike
Try the code I pasted here Sending a font file (.cpf) to zebra Qln320 printer over WLAN
I store font files in Oracle DB, load them to Windows CE device and send'em via BT to device. The only "bad thing" in this method is that printer off after each file downloading (buy the way when you load font file via USB from LabelVista the problem the same).
To delete file from printer you can use this String.Format("! U1 do \"file.delete\" \"{0}\"\r\n", FileName.ToUpper());
You can use "Zebra Setup Utilitites" to manage your printers. This software allows you to communicate with your printers and to configure them.

list of uids / names of System Preferences > Accounts

How can I obtain an array with uid and names?
I could iterate from 0 to 99999 and do a getpwnam().
However most machines have less than 5 accounts, so it's not optimal. I don't know what framework is responsible for this and thus I have no clue what to search for.
Is there a more optimal solution that can traverse the accounts?
Edit: Right after I posted I discovered getpwent() for traversing accounts.
setpwent();
struct passwd *pw;
while ((pw = getpwent())) printf("%d\n", pw->pw_uid);
endpwent();
However that doesn't indicate wether an account is a System Preferences account or not.
So still how does one obtain the System Preferences accounts?
Edit: I have found the commandline equivalent of this, the dscl command.
prompt> dscl . -list /Users UniqueID
_mysql 74
_postfix 27
_spotlight 89
_sshd 75
_windowserver 88
_www 70
daemon 1
johndoe 501
nobody -2
root 0
Use getgrnam("staff") to get a group record for the staff group. The gr_mem member, while not explained in detail by the manpage, appears to be an array of user names terminated by a NULL pointer.
To find which users are administrators, do the same thing with the admin group.

Scancode when I press a key is different. Is Microsoft specification wrong?

I am using Windows XP pro SP3. Standard english keyboard. I live in the USA; never touched the keyboard settings. Stock install. So, when I press check the scancodes my program is returning they are as follows:
A = 30
S = 31
D = 32
F = 33
G = 34
When I check the microsoft specification (page 11 of the document:: http://download.microsoft.com/download/1/6/1/161ba512-40e2-4cc9-843a-923143f3456c/scancode.doc ) It says:
A = 31
S = 32
D = 33
F = 34
G = 35
They are off by 1! Any ideas why?
The Microsoft Keyboard Scan Code Specification you quoted has six columns. For the A key:
key location: 31
keyboard: A
scan 1 make: 1E
scan 1 break: 9E
scan 2 make: 1C
scan 2 break: F0 1C
It looks like that "scan 2" set is an alternate hardware scan code that's different from the original IBM PC scan code ("scan 1"). Note that the "key location" is 31 and the "scan 1 make" is 30. This might help explain what you're seeing with the values you originally posted. Perhaps you could try looking at keys such as Esc and ` that are quite different in each set (and not just off by one, which I think is misleading).
You didn't say which API or Windows message you were using to get the scan code values you reported, but if you look in the detailed documentation for whatever you're using you might find more information.
Is the keyboard faulty at the hardware level or there is a problem with the keyboard driver can you ascertain?

Resources