Mac maniac

    Hello! This is my first habratopik (not counting the sandbox)
    and I don’t even know if anyone will see it or not :-)
    Well, I like some Mac chips which are not in Windows. Whenever possible, I write them in the scripting language AutoHotKey so as not to feel deprived) What? You still do not know about this language? Well, more likely here www.autohotkey.com . Although this can be written in almost any full-fledged language, but I will give examples on this, because the main thing is the idea.
    It might be useful to someone.
    Displaying connected devices and removing them
    It’s all the same convenient when the shortcut of the newly connected device appears on the desktop. And it’s also convenient to extract it simply by moving to the icon meaning extraction. Of course, there are different utilities for this process (for example DeskDrive

    ) but unfortunately it does not allow you to simply remove the CD / USB by simply transferring it to the treasured button. In My case, the extraction icon is just a shortcut to a compiled EXE that extracts device letters from Drag`n`Drop (yes, it’s 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 need to click "rename" and hold ALT in the input field and quickly type 0160 on the NumPad. This combination will put an invisible character. in order for all the shortcuts on the desktop to be such, it is necessary to do this nth number of times for each shortcut so that the names do not match.
    exe + icon here
    To begin with, consider the extraction program:
    (simple version. we throw device shortcuts to eat - they are extracted)
    #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. complex with "a bunch of bells and whistles" (Just the top link to the sophisticated version) is as follows:
    * If you throw is not a reference to the device, and the file, then move it to the trash (good old the MAC)
    * exact same fate befall the link is not on the device as such the folder \ file in the device
    * is the same with the link to the Hard Drives. No need to retrieve them :-)
    * when starting the program without parameters (just double click), the program checks
    all the devices are ready and updates the shortcuts on the desktop (removes unnecessary, adds the necessary) and we take the icons and names for the devices from the exe-shnik folder “ico”. I think the format of the icon names is clear: (J) Soap dish.ico - this means that this is an icon for the device J and the name on the desktop will be “Soap box”.

    But something is missing, feel? Yeah! I want the icons to appear on the desktop as they connect! But here there is one caveat - for this it is necessary that the program always hangs in memory, catching the WM_DEVICECHANGE message, and few will agree to this. But still, if all of a sudden:
    Code + Exe
    Mirror (Webfile.ru)
    Of course, there are some bugs: for example, it often does not work correctly with card readers, 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 the soup will be poured :-)

    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 the topic of Mac Maniac or " I'm too poor for MAC ":-)

    Also popular now: