Ошибка ahk an older instance

  • Members
  • 280 posts
  • Last active: Jan 09 2013 02:15 PM
  • Joined: 17 Feb 2005

I use

#SingleInstance force

on the very beginning of my script.
Still I receive the annoying message when starting another instance:

An older instance of this script is already running. Replace it with this instance?
Note: To avoid this message, see #SingleInstance in the help file.

#1

Posted 15 April 2005 — 12:45 PM

Is there another word for synonym?

  • Back to top



TeknoMusicMan

  • Members
  • 186 posts
  • Last active: Jan 17 2007 10:17 PM
  • Joined: 14 Apr 2005

Maybe try using the Reload command

you could setup a key to execute the reload command and that would be the same as using #SingleInstance force

#2

Posted 15 April 2005 — 03:15 PM

  • Back to top



Chris

  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004

I couldn’t reproduce this problem. Try running the following script:

#SingleInstance force
MsgBox Launch the script again *without* closing this dialog.

If it works there, perhaps there is something unusual about your other script that prevents it from working. If so, I’d like to work with you to try to fix it.

#3

Posted 15 April 2005 — 04:11 PM

  • Back to top



niwi

  • Members
  • 140 posts
  • Last active: Feb 04 2013 02:51 PM
  • Joined: 27 Feb 2005

Hi SanskritFritz,

a stupid question, but which version do you use?

NiWi.

#4

Posted 16 April 2005 — 04:17 PM

  • Back to top



SanskritFritz

  • Members
  • 280 posts
  • Last active: Jan 09 2013 02:15 PM
  • Joined: 17 Feb 2005

I couldn’t reproduce this problem. Try running the following script:
#SingleInstance force
MsgBox Launch the script again *without* closing this dialog.
If it works there, perhaps there is something unusual about your other script that prevents it from working. If so, I’d like to work with you to try to fix it.

You are right, the above script works ok, no warning message appears. My script contains some sensitive personal data, so before i post it here i have to strip it. But generally i have an autoexecute section where i modify the tray menu a bit and start a timer (250ms), then the subroutine for the timer where i auto close some windows and auto login to some systems as the login window appears, then lots of hotstrings, some window sensitive, and then lots of hotkeys where i modify many aspects of many applications. I also have some #includes for scripts i have downloaded: Volume OSD, and EasyWindowDrag. I had to split Volume OSD to an autoexecute section and a hotkey section, and include them separately. Feel free to ask more, i will post my script here on demand, but strip it first. Or i will try to reproduce it on a shorter version.
niwi, I use AHK Version 1.0.31.03.

#5

Posted 17 April 2005 — 08:24 PM

Is there another word for synonym?

  • Back to top



Chris

  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004

Thanks for the description. I don’t see anything in it that would prevent #SingleInstance from working properly. It might be something simple like having another (conflicting) use of #SingleInstance further down in the script, or in one of the files that is #Included.

I’m also aware of one weakness in #SingleInstance: if a script is tied up waiting for a drive to spin up or a network connection to become available (etc.) it might be temporarily unresponsive to #SingleInstance.

Also, #SingleInstance relies on the title of the script’s main window to detect duplicate instances. If the title is altered or the script’s filename changes from one instance to the next, #SingleInstance will not work.

#6

Posted 18 April 2005 — 02:51 PM

  • Back to top



SanskritFritz

  • Members
  • 280 posts
  • Last active: Jan 09 2013 02:15 PM
  • Joined: 17 Feb 2005

It might be something simple like having another (conflicting) use of #SingleInstance further down in the script, or in one of the files that is #Included.

Thanks Chris that was the problem, so it was my fault, i forgot to delete the #SingleInstance statement in the #inlude file. Sorry for that. :oops:

#7

Posted 19 April 2005 — 08:14 AM

Is there another word for synonym?

  • Back to top



Chris

  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004

Thanks for the follow-up. You could argue that conflicting uses of #SingleInstance should be a syntax error, but it probably shouldn’t be changed now since it would break a few existing scripts.

#8

Posted 19 April 2005 — 11:14 AM

  • Back to top



SanskritFritz

  • Members
  • 280 posts
  • Last active: Jan 09 2013 02:15 PM
  • Joined: 17 Feb 2005

No, that is okay this way. You just concentrate on things much more important :-)

#9

Posted 19 April 2005 — 11:50 AM

Is there another word for synonym?

  • Back to top


— running my main script containing the following —

#Persistent
#NoEnv
#SingleInstance, Force
SetWorkingDir, %A_ScriptDir%
SetTitleMatchMode, 2

CheckForVersionUpdate:	; thank you, anonymous1184
VersionChecker := "C:\_PENsTools_\AutoHotkey_\AHK-Shorties\AHK updater by anonymous1184 v001a.ahk"
If FileExist(VersionChecker)
	RunWait, %VersionChecker%
	Else
	OutputDebug, AHK Version Checker not found in expected location!`n`n%scriptICON%
VersionChecker := ""

VerifyThisScriptRunningUIA:	; thank you, anonymous1184
If !InStr(A_AhkPath, "_UIA.exe")
	{
		newPath := RegExReplace(A_AhkPath, "\.exe", "U" (32 << A_Is64bitOS) "_UIA.exe")
		Run, % StrReplace(DllCall("Kernel32\GetCommandLine", "Str"), A_AhkPath, newPath)
		newPath := ""
		ExitApp
	} Else {
		OutputDebug, AHK is already running with UIAccess!
	}

— sometimes produces the following error —

An older instance of this script is already running. Replace it with this instance?

Note: To avoid this message, see #Singlelnstance in the help file.

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement. We’ll occasionally send you account related emails.

Already on GitHub?
Sign in
to your account

Closed

megabugman opened this issue

Feb 24, 2017

· 2 comments

Comments

@megabugman

  1. when running this code MsgBox, Hello via «Run Selected Text» a message pops up: An older instance of this script is already running. running the same code via «Run Comment Block» after commenting it out (+F1) does not trigger the «another instance» message box. IMO the latter is the expected/correct behavior.

  2. selecting and running this code

#SingleInstance Force
MsgBox, Hello

will also trigger the message

maestrith

added a commit
that referenced
this issue

Feb 27, 2017

@maestrith

-Context Menu for Undo/Redo were displaying when there was not data for them #98
-Deleting umlaut characters was causing an issue #97
-Inline commands for hotkeys were not displaying parameters #96
-Odd issue with resizing controls when clicking on Omni-Search #95
-Error message when cancelling a plugin download from menus #93
-Run Selected Text
--Added Run Selected Text to the main code and changed how it works with multiple selected lines #92
--Added Run Code Block to the main code Fixed the SingleInstance issue #91
-Ctrl+R and Ctrl+E were adding odd control characters to the script #90
-Right Click: Selection will not change when right clicking #89
-Double Click on anything like #NoEnv and it will now select the # #88
Fixed:
-Delete/Backspace would go letter by letter when using a single caret.  Multiple carets will still do this.
-If you add a space in the tab previous to the first word of a line it would crash Studi
Added:
-Command Help (F1):
--Directives now work
--Selected words will also work if it is found by AHK Studio
--No need to have the Caret after the Command

maestrith

added a commit
that referenced
this issue

Feb 27, 2017

@maestrith

-Context Menu for Undo/Redo were displaying when there was not data for them #98
-Deleting umlaut characters was causing an issue #97
-Inline commands for hotkeys were not displaying parameters #96
-Odd issue with resizing controls when clicking on Omni-Search #95
-Error message when cancelling a plugin download from menus #93
-Run Selected Text
--Added Run Selected Text to the main code and changed how it works with multiple selected lines #92
--Added Run Code Block to the main code Fixed the SingleInstance issue #91
-Ctrl+R and Ctrl+E were adding odd control characters to the script #90
-Right Click: Selection will not change when right clicking #89
-Double Click on anything like #NoEnv and it will now select the # #88
Fixed:
-Delete/Backspace would go letter by letter when using a single caret.  Multiple carets will still do this.
-If you add a space in the tab previous to the first word of a line it would crash Studi
Added:
-Command Help (F1):
--Directives now work
--Selected words will also work if it is found by AHK Studio
--No need to have the Caret after the Command

@maestrith

Addressed in 1.003.13. Please close this thread if it is fixed.

@megabugman

maestrith

added a commit
that referenced
this issue

Feb 28, 2017

@maestrith

-Context Menu: items that are not applicable are greyed out #98
-Deleting umlaut characters was causing an issue #97
-Inline commands for hotkeys were not displaying parameters #96
-Odd issue with resizing controls when clicking on Omni-Search #95
-Error message when cancelling a plugin download from menus #93
-Run Selected Text
--Added Run Selected Text to the main code and changed how it works with multiple selected lines #92
--Added Run Code Block to the main code Fixed the SingleInstance issue #91
-Ctrl+R and Ctrl+E were adding odd control characters to the script #90
-Right Click: Selection will not change when right clicking #89
-Double Click on anything like #NoEnv and it will now select the # #88
Fixed:
-Delete/Backspace would go letter by letter when using a single caret.  Multiple carets will still do this.
-If you add a space in the tab previous to the first word of a line it would crash Studi
Added:
-Command Help (F1):
--Directives now work
--Selected words will also work if it is found by AHK Studio
--No need to have the Caret after the Command

maestrith

added a commit
that referenced
this issue

Feb 28, 2017

@maestrith

-Context Menu: items that are not applicable are greyed out #98
-Deleting umlaut characters was causing an issue #97
-Inline commands for hotkeys were not displaying parameters #96
-Odd issue with resizing controls when clicking on Omni-Search #95
-Error message when cancelling a plugin download from menus #93
-Run Selected Text
--Added Run Selected Text to the main code and changed how it works with multiple selected lines #92
--Added Run Code Block to the main code Fixed the SingleInstance issue #91
-Ctrl+R and Ctrl+E were adding odd control characters to the script #90
-Right Click: Selection will not change when right clicking #89
-Double Click on anything like #NoEnv and it will now select the # #88
Fixed:
-Delete/Backspace would go letter by letter when using a single caret.  Multiple carets will still do this.
-If you add a space in the tab previous to the first word of a line it would crash Studi
Added:
-Command Help (F1):
--Directives now work
--Selected words will also work if it is found by AHK Studio
--No need to have the Caret after the Command

maestrith

added a commit
that referenced
this issue

Feb 28, 2017

@maestrith

-Context Menu: items that are not applicable are greyed out #98
-Deleting umlaut characters was causing an issue #97
-Inline commands for hotkeys were not displaying parameters #96
-Odd issue with resizing controls when clicking on Omni-Search #95
-Error message when cancelling a plugin download from menus #93
-Run Selected Text
--Added Run Selected Text to the main code and changed how it works with multiple selected lines #92
--Added Run Code Block to the main code Fixed the SingleInstance issue #91
-Ctrl+R and Ctrl+E were adding odd control characters to the script #90
-Right Click: Selection will not change when right clicking #89
-Double Click on anything like #NoEnv and it will now select the # #88
Fixed:
-Delete/Backspace would go letter by letter when using a single caret.  Multiple carets will still do this.
-If you add a space in the tab previous to the first word of a line it would crash Studi
Added:
-Command Help (F1):
--Directives now work
--Selected words will also work if it is found by AHK Studio
--No need to have the Caret after the Command

maestrith

added a commit
that referenced
this issue

Feb 28, 2017

@maestrith

-Context Menu: items that are not applicable are greyed out #98
-Deleting umlaut characters was causing an issue #97
-Inline commands for hotkeys were not displaying parameters #96
-Odd issue with resizing controls when clicking on Omni-Search #95
-Error message when cancelling a plugin download from menus #93
-Run Selected Text
--Added Run Selected Text to the main code and changed how it works with multiple selected lines #92
--Added Run Code Block to the main code Fixed the SingleInstance issue #91
-Ctrl+R and Ctrl+E were adding odd control characters to the script #90
-Right Click: Selection will not change when right clicking #89
-Double Click on anything like #NoEnv and it will now select the # #88
Fixed:
-Delete/Backspace would go letter by letter when using a single caret.  Multiple carets will still do this.
-If you add a space in the tab previous to the first word of a line it would crash Studi
Added:
-Command Help (F1):
--Directives now work
--Selected words will also work if it is found by AHK Studio
--No need to have the Caret after the Command

maestrith

added a commit
that referenced
this issue

Feb 28, 2017

@maestrith

-Zoom causing line numbers to get cropped #108
-Context Menu: items that are not applicable are greyed out #98
-Deleting umlaut characters was causing an issue #97
-Inline commands for hotkeys were not displaying parameters #96
-Odd issue with resizing controls when clicking on Omni-Search #95
-Error message when cancelling a plugin download from menus #93
-Run Selected Text
--Added Run Selected Text to the main code and changed how it works with multiple selected lines #92
--Added Run Code Block to the main code Fixed the SingleInstance issue #91
-Ctrl+R and Ctrl+E were adding odd control characters to the script #90
-Right Click: Selection will not change when right clicking #89
-Double Click on anything like #NoEnv and it will now select the # #88
Fixed:
-Delete/Backspace would go letter by letter when using a single caret.  Multiple carets will still do this.
-If you add a space in the tab previous to the first word of a line it would crash Studi
Added:
-Command Help (F1):
--Directives now work
--Selected words will also work if it is found by AHK Studio
--No need to have the Caret after the Command

maestrith

added a commit
that referenced
this issue

Feb 28, 2017

@maestrith

-Omni-Search: Removed the Omni-Search option from Omni-Search
-Zoom causing line numbers to get cropped #108
-Context Menu: items that are not applicable are greyed out #98
-Deleting umlaut characters was causing an issue #97
-Inline commands for hotkeys were not displaying parameters #96
-Odd issue with resizing controls when clicking on Omni-Search #95
-Error message when cancelling a plugin download from menus #93
-Run Selected Text
--Added Run Selected Text to the main code and changed how it works with multiple selected lines #92
--Added Run Code Block to the main code Fixed the SingleInstance issue #91
-Ctrl+R and Ctrl+E were adding odd control characters to the script #90
-Right Click: Selection will not change when right clicking #89
-Double Click on anything like #NoEnv and it will now select the # #88
Fixed:
-Delete/Backspace would go letter by letter when using a single caret.  Multiple carets will still do this.
-If you add a space in the tab previous to the first word of a line it would crash Studi
Added:
-Command Help (F1):
--Directives now work
--Selected words will also work if it is found by AHK Studio
--No need to have the Caret after the Command

maestrith

added a commit
that referenced
this issue

Feb 28, 2017

@maestrith

-Omni-Search: Removed the Omni-Search option from Omni-Search
-Zoom causing line numbers to get cropped #108
-Context Menu: items that are not applicable are greyed out #98
-Deleting umlaut characters was causing an issue #97
-Inline commands for hotkeys were not displaying parameters #96
-Odd issue with resizing controls when clicking on Omni-Search #95
-Error message when cancelling a plugin download from menus #93
-Run Selected Text
--Added Run Selected Text to the main code and changed how it works with multiple selected lines #92
--Added Run Code Block to the main code Fixed the SingleInstance issue #91
-Ctrl+R and Ctrl+E were adding odd control characters to the script #90
-Right Click: Selection will not change when right clicking #89
-Double Click on anything like #NoEnv and it will now select the # #88
Fixed:
-Delete/Backspace would go letter by letter when using a single caret.  Multiple carets will still do this.
-If you add a space in the tab previous to the first word of a line it would crash Studi
Added:
-Command Help (F1):
--Directives now work
--Selected words will also work if it is found by AHK Studio
--No need to have the Caret after the Command

maestrith

added a commit
that referenced
this issue

Feb 28, 2017

@maestrith

-Omni-Search: Removed the Omni-Search option from Omni-Search
-Zoom causing line numbers to get cropped #108
-Context Menu: items that are not applicable are greyed out #98
-Deleting umlaut characters was causing an issue #97
-Inline commands for hotkeys were not displaying parameters #96
-Odd issue with resizing controls when clicking on Omni-Search #95
-Error message when cancelling a plugin download from menus #93
-Run Selected Text
--Added Run Selected Text to the main code and changed how it works with multiple selected lines #92
--Added Run Code Block to the main code Fixed the SingleInstance issue #91
-Ctrl+R and Ctrl+E were adding odd control characters to the script #90
-Right Click: Selection will not change when right clicking #89
-Double Click on anything like #NoEnv and it will now select the # #88
Fixed:
-Delete/Backspace would go letter by letter when using a single caret.  Multiple carets will still do this.
-If you add a space in the tab previous to the first word of a line it would crash Studi
Added:
-Command Help (F1):
--Directives now work
--Selected words will also work if it is found by AHK Studio
--No need to have the Caret after the Command

maestrith

added a commit
that referenced
this issue

Feb 28, 2017

@maestrith

-Omni-Search: Removed the Omni-Search option from Omni-Search
-Zoom causing line numbers to get cropped #108
-Context Menu: items that are not applicable are greyed out #98
-Deleting umlaut characters was causing an issue #97
-Inline commands for hotkeys were not displaying parameters #96
-Odd issue with resizing controls when clicking on Omni-Search #95
-Error message when cancelling a plugin download from menus #93
-Run Selected Text
--Added Run Selected Text to the main code and changed how it works with multiple selected lines #92
--Added Run Code Block to the main code Fixed the SingleInstance issue #91
-Ctrl+R and Ctrl+E were adding odd control characters to the script #90
-Right Click: Selection will not change when right clicking #89
-Double Click on anything like #NoEnv and it will now select the # #88
Fixed:
-Delete/Backspace would go letter by letter when using a single caret.  Multiple carets will still do this.
-If you add a space in the tab previous to the first word of a line it would crash Studi
Added:
-Command Help (F1):
--Directives now work
--Selected words will also work if it is found by AHK Studio
--No need to have the Caret after the Command

2 participants

@maestrith

@megabugman

Перейти к содержимому раздела

Серый форум

разработка скриптов

Вы не вошли. Пожалуйста, войдите или зарегистрируйтесь.

AHK: Настройка запуска/перезапуска скрипта

Страницы 1

Чтобы отправить ответ, вы должны войти или зарегистрироваться

1 2023-04-16 22:51:15

  • marusa122
  • Участник
  • Неактивен
  • Рейтинг : [0|0]

Тема: AHK: Настройка запуска/перезапуска скрипта

Здравствуйте!
Есть скрипт с названием Script.ahk — появление MsgBox1 с текстом «Программа запущена». При запуске скрипта Autohotkey должен проверять, был ли он запущен ранее и не закрыт. Если да — выполнять перезапуск, сообщать об этом с помощью другого MsgBox (MsgBox2) и после этого запускать скрипт. Пыталась написать такой скрипт, но он просто перезапускается без появления MsgBox2. Что я делаю не так?

process, exist, Script.ahk ;проверяет, был ли запущен ранее такой же скрипт
if errorlevel1
	{
	#SingleInstance Force
	MsgBox, 48, Перезапуск, Выполняется перезапуск Script. Программа будет открыта через несколько секунд..., 2 ;это MsgBox2
	MsgBox, 64, Готово, Script запущен!, ;это MsgBox1
	}
else
{
MsgBox, 64, Готово, Script запущен!, ;это MsgBox1
}

2 Ответ от teadrinker 2023-04-17 00:59:42

  • teadrinker
  • Администратор
  • Неактивен

Re: AHK: Настройка запуска/перезапуска скрипта

marusa122 пишет:

Что я делаю не так?

Похоже, не можете сами точно сформулировать задачу.

marusa122 пишет:

Если да — выполнять перезапуск

Перезапуск чего, себя, или другого скрипта?

marusa122 пишет:

сообщать об этом с помощью другого MsgBox (MsgBox2)

Сообщать до перезапуска, или после?

marusa122 пишет:

и после этого запускать скрипт

Так мы же вроде его уже запустили?
Я запутался!

Разработка AHK-скриптов:
e-mail dfiveg@mail.ru
Telegram jollycoder

3 Ответ от EV 2023-04-17 01:16:27 (изменено: EV, 2023-04-17 01:32:52)

  • EV
  • Участник
  • Неактивен
  • Рейтинг : [1|0]

Re: AHK: Настройка запуска/перезапуска скрипта

Обратите внимание на «process, exist, Script.ahk», нет процесса Script.ahk, у всех ровных пацанов процесс Script.exe , и на if errorlevel1.
Скомпилируйте  Script.ahk в Script.exe если нужен process, exist.

4 Ответ от __Михаил__ 2023-04-17 01:43:37

  • __Михаил__
  • Разработчик
  • Неактивен

Re: AHK: Настройка запуска/перезапуска скрипта

Да собственно всё. начиная с вопроса, заканчивая кодом.

Win10x64, AHK v1.1.33.09 (Unicode 64-bit) | AHK-Wiki | Переменные и выражения | RegEx101

5 Ответ от marusa122 2023-04-17 07:57:24 (изменено: marusa122, 2023-04-17 08:07:31)

  • marusa122
  • Участник
  • Неактивен
  • Рейтинг : [0|0]

Re: AHK: Настройка запуска/перезапуска скрипта

Перезапуск чего, себя, или другого скрипта?

Перезапуск себя

Сообщать до перезапуска, или после?

До перезапуска
Извините, если я что-то упустила. Алгоритм действий скрипта должен быть таким:
1) Запускаем скрипт Script.ahk
2) Autohotkey проверяет, был ли запущен такой скрипт ранее (активен ли в данный момент такой же процесс).

  • Если да, то вместо «An older instance of this script is already running.  Replace it with this instance?» должен появиться MsgBox1 «Выполняется перезапуск программы». Этот MsgBox1 должен исчезнуть через 3 секунды. И после него должен появиться другой MsgBox2 «Программа запущена».

  • Если нет, то сразу должен появиться MsgBox2 «Программа запущена».

6 Ответ от teadrinker 2023-04-17 10:42:47

  • teadrinker
  • Администратор
  • Неактивен

Re: AHK: Настройка запуска/перезапуска скрипта

А перезапуск когда? И что в итоге, должны работать два скрипта параллельно?

Разработка AHK-скриптов:
e-mail dfiveg@mail.ru
Telegram jollycoder

7 Ответ от marusa122 2023-04-17 17:49:57 (изменено: marusa122, 2023-04-17 17:50:50)

  • marusa122
  • Участник
  • Неактивен
  • Рейтинг : [0|0]

Re: AHK: Настройка запуска/перезапуска скрипта

teadrinker перезапуск скрипта после появления MsgBox1 «Выполняется перезапуск программы».

8 Ответ от teadrinker 2023-04-17 19:17:10

  • teadrinker
  • Администратор
  • Неактивен

Re: AHK: Настройка запуска/перезапуска скрипта

Если я всё правильно понял, то так:

#SingleInstance Off
SetTitleMatchMode, 2
DetectHiddenWindows, On

if A_Args[1]
   MsgBox, 64, Готово, Script запущен!
else {
   WinGet, list, List, %A_ScriptName% ahk_class AutoHotkey
   found := false
   Loop % list
      continue
   until list%A_Index% != A_ScriptHwnd && found := true
   
   if !found
      MsgBox, 64, Готово, Script запущен!
   else {
      MsgBox, 48, Перезапуск, Выполняется перезапуск Script. Программа будет открыта через несколько секунд..., 2
      Run, % A_ScriptFullPath . " 1"
      ExitApp
   }
}

Разработка AHK-скриптов:
e-mail dfiveg@mail.ru
Telegram jollycoder

9 Ответ от marusa122 2023-04-17 19:51:53 (изменено: marusa122, 2023-04-17 19:52:30)

  • marusa122
  • Участник
  • Неактивен
  • Рейтинг : [0|0]

Re: AHK: Настройка запуска/перезапуска скрипта

teadrinker, да, оно! Только теперь в трее появляется второй-третий-четвертый значок Script.ahk после каждого перезапуска. Как это исправить? Пробовала поменять в вашем скрипте «#SingleInstance Off» на «#SingleInstance Force» — помогло, но опять пропал MsgBox2 с сообщением о перезапуске.

10 Ответ от teadrinker 2023-04-17 20:18:49

  • teadrinker
  • Администратор
  • Неактивен

Re: AHK: Настройка запуска/перезапуска скрипта

marusa122 пишет:

в трее появляется второй-третий-четвертый значок Script.ahk

Ну да, работает соответственно вашему описанию. Если скрипт уже существует, то новозапущенный скрипт выдаёт сообщение и перезапускается, соответственно, получается уже два скрипта. Если запустить ещё раз, то будет три, и т. д.

Разработка AHK-скриптов:
e-mail dfiveg@mail.ru
Telegram jollycoder

11 Ответ от marusa122 2023-04-17 21:11:49

  • marusa122
  • Участник
  • Неактивен
  • Рейтинг : [0|0]

Re: AHK: Настройка запуска/перезапуска скрипта

teadrinker а как сделать так, чтобы при перезапуске закрывалась предыдущая версия скрипта? Чтобы в трее постоянно оставался только один значок — версия скрипта, актуальная после последнего перезапуска.
Например, в скрипте автозамены. В первой версии скрипта код

Я вношу изменения в скрипт (в Блокноте). Например, добавляю еще одну замену. Сохраняю скрипт. Теперь он выглядит так:

:*:btw::by the way
:*:exp::example

Перезапускаю скрипт, чтобы изменения вступили в силу. Выскакивает «An older instance of this script is already running.  Replace it with this instance?». И пока не нажмешь «Да», новая версия версия скрипта не запустится. Цель — чтобы вместо этого оповещения выскакивал Msgbox «Выполняется перезапуск Script. Программа будет открыта через несколько секунд…», который автоматически пропадает через пару секунд, и после этого запускается обновленная версия скрипта (уже с новой добавленной автозаменой).

12 Ответ от teadrinker 2023-04-17 22:05:48

  • teadrinker
  • Администратор
  • Неактивен

Re: AHK: Настройка запуска/перезапуска скрипта

Тогда можно так:

#SingleInstance Off
SetTitleMatchMode, 2
DetectHiddenWindows, On

WinGet, list, List, %A_ScriptName% ahk_class AutoHotkey
found := false
Loop % list
   continue
until list%A_Index% != A_ScriptHwnd && found := list%A_Index%

if !found
   MsgBox, 64, Готово, Script запущен!
else {
   WinMenuSelectItem, ahk_id %found%,, File, Exit (Terminate Script)
   MsgBox, 48, Перезапуск, Script перезапущен, 2
}

Но проще было бы написать в начале #SingleInstance, Force, тогда новый скрипт будет заменять старый без всяких ухищрений.

Разработка AHK-скриптов:
e-mail dfiveg@mail.ru
Telegram jollycoder

13 Ответ от marusa122 2023-04-17 22:35:38

  • marusa122
  • Участник
  • Неактивен
  • Рейтинг : [0|0]

Re: AHK: Настройка запуска/перезапуска скрипта

teadrinker спасибо, это то, что нужно!

14 Ответ от __Михаил__ 2023-04-18 18:35:28 (изменено: __Михаил__, 2023-04-18 18:36:48)

  • __Михаил__
  • Разработчик
  • Неактивен

Re: AHK: Настройка запуска/перезапуска скрипта

Не проще ли нормальный код писать и не выдумывать всякие костыли? Задача быстро применять новые изменения в скрипте? Тогда просто добавив одну строку можно перезапускать текущий скрипт. Зачем искать его в папке, дважды кликать по нему?

Win10x64, AHK v1.1.33.09 (Unicode 64-bit) | AHK-Wiki | Переменные и выражения | RegEx101

Сообщения 14

Страницы 1

Чтобы отправить ответ, вы должны войти или зарегистрироваться

I am new to AHK.

I have been playing around with AHK and have been finding the compiling of new verisons of my scripts tedious. I think I am doing it wrong.

I have the .ahk script, then the .bak script, then the .exe file under that

I right click on the .ahk script and selct edit script.

I edit, then save the file and close the window.

I right click on the .ahk script and select compile script.

I open task manager and close the old instance of my program (the .exe)

I then double click on the .ahk script, then double click on the .exe program.

It then works.
I feel as though I am doing this badly wrong, and there is a proper version that is the real way to do it. Any help in understanding this would help a lot.

Thanks in advance

Community's user avatar

asked Apr 2, 2020 at 16:23

Malted_Wheaties's user avatar

There is no reason for you to compile your script.
Compiling is done to make portable scripts, so you could run the script on a machine that does’t have AHK installed.
So just forget about compiling.

Edit your script (the .ahk file) save it, and then double click it.
You’ll receive a prompt that an older version of that script is already running, click yes to override the older version.
To not have to click yes on a dialog, you can specify #SingleInstance, Force on top of your script. This way you automatically always replace the older version.

And the .bak file you have, is just a backup of your script.
Whatever editor you’re using the edit the .ahk files is creating that file for you. So it’s the same exact file as your .ahk file, but with just a different extension. The file has no special significance.
.ahk files are just text files, nothing else, you can edit them with any text editor of your choice.

answered Apr 2, 2020 at 16:47

0x464e's user avatar

0x464e0x464e

6,1781 gold badge12 silver badges17 bronze badges

0

Понравилась статья? Поделить с друзьями:
  • Ошибка appcrash c0000005
  • Ошибка ah сплит системы polair
  • Ошибка ah1 elitech
  • Ошибка app store платеж не выполнен
  • Ошибка ah1 ecs 974neo