Is there any way to apply labels to a folder externally?

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
rolander
Posts: 33
Joined: 22 Aug 2022 17:41

Is there any way to apply labels to a folder externally?

Post by rolander »

I work on video using a software (foundry hiero) that let me make custom tools for it in python.
I've made a a panel with color buttons so I can quickly color code my videos, and I'd like to also color code the folders containing this videos.
Is that possible some way?
Is there any txt file I might be able to access and edit maybe?
Or may you suggest any other way to accomplish that?
Thanks!

klownboy
Posts: 4176
Joined: 28 Feb 2012 19:27

Re: Is there any way to apply labels to a folder externally?

Post by klownboy »

A similar question was asked recently viewtopic.php?t=27370. Look here: https://www.xyplorer.com/release_10.80.php#CFdir
Windows 11, 23H2 Build 22631.3447 at 100% 2560x1440

rolander
Posts: 33
Joined: 22 Aug 2022 17:41

Re: Is there any way to apply labels to a folder externally?

Post by rolander »

Thanks for the quick reply.
Unfortunately it's a different question. On the other topic the user is asking for a way to automatically tag a folder by searching for something in the folder's name.
My question is how to tag a folder from outside of xyplorer. And this folder might be tagged with Red, then Green, then Blue. It's not a "search for text and tag accordingly".
Hope I had explained it properly :)

highend
Posts: 13411
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Is there any way to apply labels to a folder externally?

Post by highend »

E.g. by sending a WM_COPYDATA message with a script to tag that file / folder
One of my scripts helped you out? Please donate via Paypal

Norn
Posts: 429
Joined: 24 Oct 2021 16:10

Re: Is there any way to apply labels to a folder externally?

Post by Norn »

Or via the command line.

Code: Select all

"D:\XYplorer\XYplorer.exe" /feed=^|::tag(1, "C:\Program Files")^|
/feed

Lets you feed a script into an existing instance of XYplorer without changing the location or tabs of that instance. A practical shorthand of using switches /script and /flg=2. The following lines are functionally identical:

XYplorer.exe /script="::msg 'Hi!';" /flg=2

XYplorer.exe /feed="::msg 'Hi!';"

If you use both /script and /feed then /feed will overwrite /script.

Tip: You can "pipe" a value instead of quoting it. This can be useful when unpredictable quotes (that might be returned from variables) make predictable parsing impossible, or simply to make a string more readable. For example, this is the same Command Line Switch, first quoted then piped:

/feed="::text '"R:\a b c"';" (this would not work; parser cannot handle the ambiguous quotes)

/feed=|::text '"R:\a b c"';| (this does work)

Of course, you must be sure that no pipes can come up inside the value.

When called from a dos prompt the pipes have to be escaped, e.g.:

XYplorer.exe /feed=^|::text '"R:\a b c"';^|
Win10, Win11 @100% 2560x1440 22H2

rolander
Posts: 33
Joined: 22 Aug 2022 17:41

Re: Is there any way to apply labels to a folder externally?

Post by rolander »

highend wrote: 06 May 2024 17:18 E.g. by sending a WM_COPYDATA message with a script to tag that file / folder
I've tried every possible way to do this and I failed every time.
I dont have any errors, but I don't have any response from xyplorer neither. It doesn't matter if I try to send a msg or change a tag. I can't make it work this way.

rolander
Posts: 33
Joined: 22 Aug 2022 17:41

Re: Is there any way to apply labels to a folder externally?

Post by rolander »

Norn wrote: 06 May 2024 18:51 Or via the command line.

Code: Select all

"D:\XYplorer\XYplorer.exe" /feed=^|::tag(1, "C:\Program Files")^|
/feed

Lets you feed a script into an existing instance of XYplorer without changing the location or tabs of that instance. A practical shorthand of using switches /script and /flg=2. The following lines are functionally identical:

XYplorer.exe /script="::msg 'Hi!';" /flg=2

XYplorer.exe /feed="::msg 'Hi!';"

If you use both /script and /feed then /feed will overwrite /script.

Tip: You can "pipe" a value instead of quoting it. This can be useful when unpredictable quotes (that might be returned from variables) make predictable parsing impossible, or simply to make a string more readable. For example, this is the same Command Line Switch, first quoted then piped:

/feed="::text '"R:\a b c"';" (this would not work; parser cannot handle the ambiguous quotes)

/feed=|::text '"R:\a b c"';| (this does work)

Of course, you must be sure that no pipes can come up inside the value.

When called from a dos prompt the pipes have to be escaped, e.g.:

XYplorer.exe /feed=^|::text '"R:\a b c"';^|
This is a very straight forward solution. And it works, BUT it brings focus the xyplorer window.
Is there any way to avoid that?
Ive tried creating a script and runing it this way also: start /min "" "C:\Program Files (x86)\XYplorer\XYplorer.exe" /script="T:\Tag_Red.xys"
Again, it works but it brings the xyplorer windows to the front and it also opens a new tab on My PC.

Any ideas on how to make it work in the background?
Thanks!!

highend
Posts: 13411
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Is there any way to apply labels to a folder externally?

Post by highend »

Without any details nobody can say anything...
Correct hwnd, correct msg type, content of the script, the check what XY received (look into the scripting section, there is a command for that)...

On holiday for a week, somebody else needs to answer that^^
One of my scripts helped you out? Please donate via Paypal

admin
Site Admin
Posts: 60947
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: Is there any way to apply labels to a folder externally?

Post by admin »

Enjoy! :beer:

rolander
Posts: 33
Joined: 22 Aug 2022 17:41

Re: Is there any way to apply labels to a folder externally?

Post by rolander »

highend wrote: 07 May 2024 18:20 Without any details nobody can say anything...
Correct hwnd, correct msg type, content of the script, the check what XY received (look into the scripting section, there is a command for that)...

On holiday for a week, somebody else needs to answer that^^
Sorry but I thought it was maybe a little too much to send a python code here asking for someone to take a look at it. But if you're able to review it, I would really appreciate your insight:

Code: Select all

import ctypes
import ctypes.wintypes
import win32con
import win32gui

class COPYDATASTRUCT(ctypes.Structure):
    _fields_ = [
        ("dwData", ctypes.c_ulong),
        ("cbData", ctypes.c_ulong),
        ("lpData", ctypes.c_void_p)
    ]

def send_message_to_xyplorer(hwnd, message):
    data = message.encode('utf-8')
    cds = COPYDATASTRUCT()
    cds.dwData = 1  # Establecer en 1 para indicar que el contenido es un script
    cds.cbData = len(data) + 1  # +1 para el carácter nulo
    cds.lpData = ctypes.cast(ctypes.create_string_buffer(data), ctypes.c_void_p).value
    
    lpdata = ctypes.cast(ctypes.byref(cds), ctypes.c_void_p).value
    win32gui.SendMessage(hwnd, win32con.WM_COPYDATA, 0, lpdata)

if __name__ == "__main__":
    hwnd = 659168  # Cambia esto por el HWND real de XYplorer
    tag_command = "::tag 'Red', 'F:\\+Download';"
    send_message_to_xyplorer(hwnd, tag_command)

The script runs without errors, and it seems like the message is being sent, but I don't see any changes in XYplorer. So I'm definitely doing something wrong.
Thanks!

Norn
Posts: 429
Joined: 24 Oct 2021 16:10

Re: Is there any way to apply labels to a folder externally?

Post by Norn »

I installed Python and asked AI to convert an AutoHotkey v2 script into a Python script.
Python Send Message To XYplorer.png
Python Send Message To XYplorer.png (180.08 KiB) Viewed 514 times

Code: Select all

#Python Send Message To XYplorer
import ctypes
import ctypes.wintypes
import platform
import win32gui



def get_xy_hwnd(xy_class='ThunderRT6FormDC'):
    # 初始化一个变量来存储找到的窗口句柄
    found_hwnd = None

    # 枚举所有顶级窗口
    def enum_windows_callback(hwnd, extra):
        nonlocal found_hwnd  # 声明我们要在嵌套函数中使用外部变量

        class_name = win32gui.GetClassName(hwnd)

        if class_name == xy_class:
            # 尝试获取控件数量
            child_count = [0]  # 使用列表作为可变对象来存储计数

            def enum_child_windows_callback(hwnd_child, extra_child):
                child_count[0] += 1  # 递增计数
                return True  # 继续枚举

            win32gui.EnumChildWindows(hwnd, enum_child_windows_callback, None)

            # 如果找到了匹配的类名,并且子窗口数量足够
            if child_count[0] >= 10:
                found_hwnd = hwnd  # 更新找到的窗口句柄
                return False  # 停止枚举顶级窗口

        return True  # 继续枚举顶级窗口

    # 枚举所有顶级窗口并调用回调函数
    try:
        win32gui.EnumWindows(enum_windows_callback, None)
    except Exception as e:
        return found_hwnd

    # 返回找到的窗口句柄(如果有的话)
    return found_hwnd



# 判断系统位数
if platform.architecture()[0] == '32bit':
    ULONG_PTR = ctypes.wintypes.ULONG
else:
    ULONG_PTR = ctypes.c_uint64


# 定义 COPYDATASTRUCT 结构
class COPYDATASTRUCT(ctypes.Structure):
    _fields_ = [("dwData", ULONG_PTR),
                ("cbData", ctypes.wintypes.DWORD),
                ("lpData", ctypes.c_void_p)]


def Send_WM_COPYDATA(xyHwnd, message):
    if not xyHwnd:
        return None

        # 准备 COPYDATASTRUCT 数据
    cds = COPYDATASTRUCT()
    cds.dwData = 4194305  # 这是一个示例值,你可能需要根据你的应用来设置
    cds.cbData = len(message.encode('utf-16-le'))  # 转换为 UTF-16 字节长度
    cds_data = ctypes.create_unicode_buffer(message)
    cds.lpData = ctypes.cast(ctypes.addressof(cds_data), ctypes.c_void_p)

    # 调用 SendMessageW
    user32 = ctypes.WinDLL('user32', use_last_error=True)
    result = user32.SendMessageW(xyHwnd, 74, 0, ctypes.byref(cds))

    return result


#############################################################################
# 示例使用
hwnd = get_xy_hwnd()  # 调用函数并打印结果(你需要有一个有效的窗口句柄)
message = "::msg 1"
result = Send_WM_COPYDATA(hwnd, message)
Win10, Win11 @100% 2560x1440 22H2

rolander
Posts: 33
Joined: 22 Aug 2022 17:41

Re: Is there any way to apply labels to a folder externally?

Post by rolander »

Brilliant!! Works great.
Using this script I can tag my folders in the background.
Thanks a lot for taking the time to do this :) Really appreciated

kiwichick
Posts: 577
Joined: 08 Aug 2012 04:14
Location: Pahiatua, New Zealand

Re: Is there any way to apply labels to a folder externally?

Post by kiwichick »

Norn wrote: 08 May 2024 14:46 asked AI to convert an AutoHotkey v2 script into a Python script.
Can you please tell me how you did that? Thanks.
Windows 10 Pro 22H2

Norn
Posts: 429
Joined: 24 Oct 2021 16:10

Re: Is there any way to apply labels to a folder externally?

Post by Norn »

I did not send the complete AuotHotkey script to ask AI at the beginning, but divided it into two parts according to the function, and then asked AI to get the code for testing. Sometimes you may need to slightly modify a few statements, or ask AI for solutions, and finally merge them to get Valid script.
Although AI is still just a baby, it can already help us write and convert most codes, which will save a lot of time for people who are not skilled in programming.
Win10, Win11 @100% 2560x1440 22H2

kiwichick
Posts: 577
Joined: 08 Aug 2012 04:14
Location: Pahiatua, New Zealand

Re: Is there any way to apply labels to a folder externally?

Post by kiwichick »

Norn wrote: 15 May 2024 04:15 I did not send the complete AuotHotkey script to ask AI at the beginning, but divided it into two parts according to the function, and then asked AI to get the code for testing. Sometimes you may need to slightly modify a few statements, or ask AI for solutions, and finally merge them to get Valid script.
Although AI is still just a baby, it can already help us write and convert most codes, which will save a lot of time for people who are not skilled in programming.
Thanks and, sorry, my question should have been more clear. I understand your answer but that wasn't what I meant. I was wondering how you went about it. Did you use an online site via browser? An AI app? The desktop Python app?
Windows 10 Pro 22H2

Post Reply