📜 ⬆️ ⬇️

Mac maniac

Hello! This is my first habratopic (not counting the sandbox)
and I don't even know if anyone will see it or not :-)
Well, I like some chips on the Mac which are not in Windows. As far as possible I write them in the AutoHotKey scripting language so as not to feel deprived) What? Don't you know about this language yet? Well, well, rather here www.autohotkey.com . Although it can be written in almost any full-fledged language, I will give examples on this, because the main thing is the idea.
Maybe it will seem useful to someone.
Displaying connected devices and retrieving them
How convenient is it when a shortcut of a newly connected device appears on the desktop? And it is also convenient to extract it simply by moving the icon meaning extraction.

Of course, there are different utilities for this process (for example, DeskDrive ), but unfortunately it does not allow you to remove the CD / USB by simply transferring to the cherished button. In my case, the extraction icon is just a shortcut to a compiled EXE, which extracts the letters of devices from Drag`n`Drop (yes, it is possible to select them all and drop them there and they will all be extracted (and CD / DVD too)). So that the label does not display the name, you must click "rename" and in the input field hold ALT and quickly type on NumPad ʻe 0160. This combination will put an invisible character. in order for all shortcuts on the desktop to be such, it is necessary to do this for the shortcut n-th number of times so that the names do not match.
exe + icon here
First, consider the extraction program:
(simple version. we throw the device labels to the food - they are removed)
#NoEnv
#NoTrayIcon

Loop ; .
{
curr:=%A_Index% ;A_Index -

; := %% curr
; 1,2,3... %1%, %2%, .... -

if(curr="") ; :-)
ExitApp ;

FileGetShortcut, %curr%, OutTarget ; Target
Driveletter := SubStr(OutTarget,1,2) ;
;======== Help AutoHotKey=====
hVolume := DllCall("CreateFile"
, Str, "\\.\" . Driveletter
, UInt, 0x80000000 | 0x40000000 ; GENERIC_READ | GENERIC_WRITE
, UInt, 0x1 | 0x2 ; FILE_SHARE_READ | FILE_SHARE_WRITE
, UInt, 0
, UInt, 0x3 ; OPEN_EXISTING
, UInt, 0, UInt, 0)
if hVolume <> -1
{
DllCall("DeviceIoControl" ; USB, CD
, UInt, hVolume
, UInt, 0x2D4808 ; IOCTL_STORAGE_EJECT_MEDIA
, UInt, 0, UInt, 0, UInt, 0, UInt, 0
, UIntP, dwBytesReturned ; Unused.
, UInt, 0)
DllCall("CloseHandle", UInt, hVolume)
}
FileRecycle, %curr% ;
}
return

But it was a simple version. complicated with a “bunch of frills” (Just at the top of the link to a complex version) looks like this:
* if the throw is not a link to the device, but a file, then move it to the trash (good old MAC)
* The same fate will comprehend the link not to the device but for example to the folder \ file in the device
* The same is true for Hard Disks. Do not extract them :-)
* when the program is started without parameters (just a double-click), the program checks
all devices for readiness and updates the shortcuts on the desktop (deletes unnecessary, adds the necessary) and take the Icons and the names of the devices from the folder exe-shnik "ico". The format of the icon names I think is clear: (J) Soap tray. Pic - this means that this is an icon for device J and the name on the desktop will be “Soap tray”.

But something is missing, feel? Aha I want the icons to appear on the desktop themselves as they are connected! But here there is one nuance - for this it is necessary that the program always hang in memory, catching the WM_DEVICECHANGE message, and few people will agree to this. But still if suddenly:
Code + Exe
Mirror (Webfile.ru)
Of course there are some bugs: for example, card readers often do not work correctly, but this is because for some reason the system does not send WM_DEVICECHANGE when removing or inserting a memory card into the card reader (does anyone know the solution?
since it was tested only on my machine (XP SP3), then I think that it will run like a river :-)

ps: Icons can be taken here:
deviantArt.com
allday.ru (only after registration)
www.iconspedia.com
pps: as if this is not the last topic on Mac Maniac or "I am too poor for MAC" :-)

')

Source: https://habr.com/ru/post/50707/


All Articles