Jump to content
Macro Express Forums

If doesn't work with copying/moving files window


Recommended Posts

Hello,

 

Sometimes it takes a long time to copy/move my files.

I wrote a code using the Macro application to shut down my computer as soon as this window is closed.

However the If condition does not work properly with the File copy/move window.

I'll be happy if you can help me.

 

ps: I am using the Turkish language. I can find the copy window with the title "tamamlandı". (Of course Partial Matching. Full title ex "53% tamamlandı")

 

 

<VARIABLE SET INTEGER Option="\x00" Destination="%N[1]%" Value="0"/>
<REPEAT UNTIL Variable="%N[1]%" Condition="\x00" Value="1"/>
<IF NOT WINDOW Option="\x01" Title=" tamamlandı" Partial="TRUE" Wildcards="FALSE"/>
<VARIABLE SET INTEGER Option="\x00" Destination="%N[1]%" Value="1"/>
<END IF/>
<END REPEAT/>
<DELAY Flags="\x01" Time="5"/>
<MESSAGEBOX Caption="PENCERE" Message="PENCERE KAPANDI" Icon="0"/>

 

Link to comment
Share on other sites

I am using Macro Express Pro 6.6.1.1.  I had a strange problem recently where "IF WINDOW IS FOCUSED" worked properly, but "IF WINDOW IS NOT FOCUSED" did not work.  So you could flip your logic and see if that helps. 

 

I never did resolve whether my problem was Macro Express or just some dumb mistake by me -- I just took the path of least resistance and used the different instruction. 

 

Link to comment
Share on other sites

1 hour ago, rberq said:

I am using Macro Express Pro 6.6.1.1.  I had a strange problem recently where "IF WINDOW IS FOCUSED" worked properly, but "IF WINDOW IS NOT FOCUSED" did not work.  So you could flip your logic and see if that helps. 

 

I never did resolve whether my problem was Macro Express or just some dumb mistake by me -- I just took the path of least resistance and used the different instruction. 

 

 

Thank you for your answer.

The code I am currently using works with Window Focusing logic.

 

<WINDOW ACTIVATE Title="tamamlandı" Exact_Match="FALSE" Wildcards="FALSE" _IGNORE="0x0006"/>
<WAIT FOR WINDOW TO LOSE FOCUS Title="tamamlandı" Partial="TRUE" Wildcards="TRUE" Indefinite="TRUE" Hours="0" Minutes="0" Seconds="0"/>
<DELAY Flags="\x01" Time="5"/>
<POWER OFF COMPUTER/>

 

However, the focus of the window may be lost when another application/notification etc. arrives and the PC may shut down before the copying/moving process is completed. Unfortunately I need to find a more stable solution.

 

 

Link to comment
Share on other sites

1 minute ago, Cory said:

Use the MEP commands to manipulate the files. 

Thank you for your answer.

Unfortunately, I don't know much about the application. Sorry for that.

What do you mean by "Use the MEP commands to manipulate the files"?

Could you give me an example?

Link to comment
Share on other sites

4 hours ago, tass_co said:

However, the focus of the window may be lost when another application/notification etc. arrives and the PC may shut down before the copying/moving process is completed. Unfortunately I need to find a more stable solution.

 

Yes, I know I said "focused" and your macro said "running".  But my point was, you could try changing your logic to avoid using the "not" condition.  See below.  

 

Also I notice there is a blank space before the word tamamlandi -- will there ALWAYS be a blank space there?  

 

And you might want to move the Delay before End Repeat instead of after, so as to make a less-intensive loop.  

 

Variable Set Integer %N[1]% to 0
Repeat Until %N[1]% Equals "1"
  If Window " tamamlandi" is running
  Else
    Variable Set Integer %N[1]% to 1
  End If
  Delay: 5 seconds     <<<<<<<<<<  Here instead of after End Repeat ???
End Repeat
MessageBox: PENCERE

 

Link to comment
Share on other sites

I wonder if something like this might do what you need to do:

 

Repeat Start (Repeat 10 times)
  Window Activate: tamamlandi
  Delay: 500 milliseconds
  If Window "tamamlandi" is focused
    Continue
  Else
    Power Off Computer
    Macro Stop
  End If
End Repeat
MessageBox: "tamamlandi" did not appear within 5 seconds


<REPEAT START Start="1" Step="1" Count="10" Save="FALSE"/>
<WINDOW ACTIVATE Title="tamamlandi" Exact_Match="FALSE" Wildcards="FALSE"/>
<DELAY Flags="\x02" Time="500"/>
<IF WINDOW Option="\x00" Title="tamamlandi" Partial="TRUE" Wildcards="FALSE"/>
<CONTINUE/>
<ELSE/>
<POWER OFF COMPUTER/>
<MACRO STOP/>
<END IF/>
<END REPEAT/>
<MESSAGEBOX Caption="\"tamamlandi\" did not appear within 5 seconds" Message="Try again!" Icon="4"/>

 

Link to comment
Share on other sites

1 hour ago, rberq said:

 

Yes, I know I said "focused" and your macro said "running".  But my point was, you could try changing your logic to avoid using the "not" condition.  See below.  

 

Also I notice there is a blank space before the word tamamlandi -- will there ALWAYS be a blank space there?  

 

And you might want to move the Delay before End Repeat instead of after, so as to make a less-intensive loop.  

 

Variable Set Integer %N[1]% to 0
Repeat Until %N[1]% Equals "1"
  If Window " tamamlandi" is running
  Else
    Variable Set Integer %N[1]% to 1
  End If
  Delay: 5 seconds     <<<<<<<<<<  Here instead of after End Repeat ???
End Repeat
MessageBox: PENCERE

 

 

There will always be a space in front of "tamamlandı".

Because Windows always shows the percentage in the title when copying/moving files.

 

I added the delay for measure. Location does not matter.

 

I tried the code you shared. Unfortunately, it does nothing when the copy is completed. It stays in the if loop :(

Link to comment
Share on other sites

19 minutes ago, acantor said:

I wonder if something like this might do what you need to do:

 

Repeat Start (Repeat 10 times)
  Window Activate: tamamlandi
  Delay: 500 milliseconds
  If Window "tamamlandi" is focused
    Continue
  Else
    Power Off Computer
    Macro Stop
  End If
End Repeat
MessageBox: "tamamlandi" did not appear within 5 seconds


<REPEAT START Start="1" Step="1" Count="10" Save="FALSE"/>
<WINDOW ACTIVATE Title="tamamlandi" Exact_Match="FALSE" Wildcards="FALSE"/>
<DELAY Flags="\x02" Time="500"/>
<IF WINDOW Option="\x00" Title="tamamlandi" Partial="TRUE" Wildcards="FALSE"/>
<CONTINUE/>
<ELSE/>
<POWER OFF COMPUTER/>
<MACRO STOP/>
<END IF/>
<END REPEAT/>
<MESSAGEBOX Caption="\"tamamlandi\" did not appear within 5 seconds" Message="Try again!" Icon="4"/>

 

 

Thank you for your answer.

I use 2 PCs. One is for download purposes only. The time it takes to copy files from one to another varies depending on file size. For example, I am transferring a 200GB file. ıt takes 1 hours. Therefore, I think the repetition time of the code you shared will sometimes be sufficient and sometimes not. Please correct me if I'm wrong.

 

Link to comment
Share on other sites

MEP = Macro Express Pro. It's the software this form is dedicated to. 

MEP has commands to manipulate files like moving them without using File Explorer. If MEP moves the files it knows when it's complete and can go to the command to shut down. All commands > Files and Folders > Move File/Files. Or whichever manipulation you are performing. There is a help section on it to get you started. 

Link to comment
Share on other sites

1 minute ago, Cory said:

MEP = Macro Express Pro. It's the software this form is dedicated to. 

MEP has commands to manipulate files like moving them without using File Explorer. If MEP moves the files it knows when it's complete and can go to the command to shut down. All commands > Files and Folders > Move File/Files. Or whichever manipulation you are performing. There is a help section on it to get you started. 

Oh sorry :) I thought you were talking about something else.

 

I have to use File Explorer to copy files. Because I decide which files to copy by considering the space on the disks.

Link to comment
Share on other sites

You may be able to use Macro Express to decide when to copy a file -- without using File Explorer. Macro Express can determine the size of a file.

 

 

// Assign the name of a file to variable %FileName% (not sure how to do this, but I think it's possible!)
// (You'll need to figure out how to do this.)

Variable Set Integer %SizeOfFile% to the size of %FileName%

If Variable %FileSize% Is Greater Than "1000"
  Copy File/Files: "%FileName%" to "c:\Temporary\%FileName%"
End If

 

Link to comment
Share on other sites

1 hour ago, acantor said:

You may be able to use Macro Express to decide when to copy a file -- without using File Explorer. Macro Express can determine the size of a file.

 

 

// Assign the name of a file to variable %FileName% (not sure how to do this, but I think it's possible!)
// (You'll need to figure out how to do this.)

Variable Set Integer %SizeOfFile% to the size of %FileName%

If Variable %FileSize% Is Greater Than "1000"
  Copy File/Files: "%FileName%" to "c:\Temporary\%FileName%"
End If

 

Thank you for offering a different solution, but I do not want to complicate the code when there is a much easier way to do it. I want to make a command or application that will run when the copy window is closed.

Link to comment
Share on other sites

I see one big problem in your original code. You don't have any delay in your repeat loop. This is a terrible practice. Use at least 100 or 1000 ms. It can get behind and suck up huge amounts of CPU. Try adding a delay. 

Also does the command to shutdown the computer work without the loop? I was thinking you might need ot run it with administrative privileges. Some commands just won't work without them.

YOu might have addressed this before, but there's a space in "If Not Window"

Also be aware that MEP is not capable of Unicode. Needs to be only ASCII/ANSI. 

Link to comment
Share on other sites

On 10/20/2023 at 3:03 AM, Cory said:

I see one big problem in your original code. You don't have any delay in your repeat loop. This is a terrible practice. Use at least 100 or 1000 ms. It can get behind and suck up huge amounts of CPU. Try adding a delay. 

Also does the command to shutdown the computer work without the loop? I was thinking you might need ot run it with administrative privileges. Some commands just won't work without them.

YOu might have addressed this before, but there's a space in "If Not Window"

Also be aware that MEP is not capable of Unicode. Needs to be only ASCII/ANSI. 

 

 

Thank you again for your answer.
As I said before, I don't know much about coding.
As you said, I thought there might be a problem due to the "space" in the window title.
Based on this, I tried to handle the "percentage" part and the code gave positive results.
The working code is below.

 

<VARIABLE SET INTEGER Option="\x00" Destination="%N[1]%" Value="0"/>
<REPEAT UNTIL Variable="%N[1]%" Condition="\x00" Value="1"/>
<IF WINDOW Option="\x01" Title="100%  tamamlandı" Partial="TRUE" Wildcards="TRUE"/>
<VARIABLE SET INTEGER Option="\x00" Destination="%N[1]%" Value="1"/>
<DELAY Flags="\x01" Time="2"/>
<END IF/>
<DELAY Flags="\x01" Time="10"/>
<END REPEAT/>
<POWER OFF COMPUTER _ENABLED="FALSE"/>

 

 

I would like to thank all my friends who responded and tried to help.
Respects

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...