diff --git a/about/help_en b/about/help_en
index c4b9149..48e3a24 100644
--- a/about/help_en
+++ b/about/help_en
@@ -164,6 +164,7 @@ Tenmon can be executed from command line. It support these command line options.
--thumb, --thumbnail <path> Generate thumbnail and save it to path. It generate it from first file provided as argument.
-s, --size size of generated thumbnail. Aspect ratio of input image is preserved.
--script <script> execute a script from file path same manner as executed from GUI.
+--scriptarg <arg>>; pass this string as variable scriptarg to a running script.
--outdir <dir> output dir for script execution. By default current working directory is used.
--noexit by default application exit when execution of script specified with --script ends. This prefent that.
-h, --help show help end exit.
diff --git a/about/help_fr b/about/help_fr
index eaf3cfe..f528609 100644
--- a/about/help_fr
+++ b/about/help_fr
@@ -144,6 +144,7 @@ Tenmon can be executed from command line. It support these command line options.
--thumb, --thumbnail <path> Generate thumbnail and save it to path. It generate it from first file provided as argument.
-s, --size size of generated thumbnail. Aspect ratio of input image is preserved.
--script <script> execute a script from file path same manner as executed from GUI.
+--scriptarg <arg>>; pass this string as variable scriptarg to a running script.
--outdir <dir> output dir for script execution. By default current working directory is used.
--noexit by default application exit when execution of script specified with --script ends. This prefent that.
-h, --help show help end exit.
diff --git a/about/help_sk b/about/help_sk
index e7e8cd3..77b75e5 100644
--- a/about/help_sk
+++ b/about/help_sk
@@ -144,6 +144,7 @@ Tenmon can be executed from command line. It support these command line options.
--thumb, --thumbnail <path> Generate thumbnail and save it to path. It generate it from first file provided as argument.
-s, --size size of generated thumbnail. Aspect ratio of input image is preserved.
--script <script> execute a script from file path same manner as executed from GUI.
+--scriptarg <arg>>; pass this string as variable scriptarg to a running script.
--outdir <dir> output dir for script execution. By default current working directory is used.
--noexit by default application exit when execution of script specified with --script ends. This prefent that.
-h, --help show help end exit.
diff --git a/src/batchprocessing.cpp b/src/batchprocessing.cpp
index caccd5d..fd83aa0 100644
--- a/src/batchprocessing.cpp
+++ b/src/batchprocessing.cpp
@@ -185,7 +185,7 @@ void BatchProcessing::refreshPaths()
for(int i=0; i<_ui->pathsList->count(); i++)
paths.append(_ui->pathsList->item(i)->text());
_paths = scanDirectories(paths);
- _engine->setParams("", _paths, _ui->outputPath->text());
+ _engine->setParams("", _paths, _ui->outputPath->text(), QString());
}
void BatchProcessing::addFiles()
@@ -268,7 +268,7 @@ void BatchProcessing::runScript()
else
script = ":/scripts/" + script;
- _engineThread->setParams(script, _paths, _ui->outputPath->text());
+ _engineThread->setParams(script, _paths, _ui->outputPath->text(), QString());
_engineThread->start();
_ui->startButton->setEnabled(false);
_ui->stopButton->setEnabled(true);
@@ -282,7 +282,7 @@ void BatchProcessing::runScript()
}
}
-void BatchProcessing::runScript(const QString &script, bool exit)
+void BatchProcessing::runScript(const QString &script, const QString &arg, bool exit)
{
_ui->log->clear();
{
@@ -295,7 +295,7 @@ void BatchProcessing::runScript(const QString &script, bool exit)
QFileInfo outDir(_ui->outputPath->text());
if(outDir.exists() && outDir.isWritable())
{
- _engineThread->setParams(script, _paths, _ui->outputPath->text());
+ _engineThread->setParams(script, _paths, _ui->outputPath->text(), arg);
_engineThread->start();
_ui->startButton->setEnabled(false);
_ui->stopButton->setEnabled(true);
diff --git a/src/batchprocessing.h b/src/batchprocessing.h
index 4ba7349..6caf366 100644
--- a/src/batchprocessing.h
+++ b/src/batchprocessing.h
@@ -44,7 +44,7 @@ public slots:
void browse();
void openScriptDir();
void runScript();
- void runScript(const QString &script, bool exit);
+ void runScript(const QString &script, const QString &arg, bool exit);
void stopScript();
void scriptFinished();
void newMessage(const QString &message, bool error);
diff --git a/src/main.cpp b/src/main.cpp
index be3c163..b56370c 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -37,6 +37,7 @@ int main(int argc, char *argv[])
cmd.addOption({{"s", "size"}, "Size of the thumbnails in pixels (default: 128)", "size", "128"});
cmd.addPositionalArgument("file", "Files or paths to open");
cmd.addOption({"script", "Execute script", "script"});
+ cmd.addOption({"scriptarg", "String that will be passed to script as variable \"scriparg\"", "arg"});
cmd.addOption({"outdir", "Output dir for script (default: CWD)", "dir", "."});
cmd.addOption({"noexit", "Do not exit application when script finish"});
cmd.addHelpOption();
@@ -132,11 +133,12 @@ int main(int argc, char *argv[])
QStringList paths = cmd.positionalArguments();
QString script = cmd.value("script");
QString outdir = cmd.value("outdir");
+ QString arg = cmd.value("scriptarg");
if(!QDir::isAbsolutePath(script))script = QDir::currentPath() + "/" + script;
if(!QDir::isAbsolutePath(outdir))outdir = QDir::currentPath() + "/" + outdir;
bool noexit = cmd.isSet("noexit");
if(!noexit)w.hide();
- w.runScript(script, outdir, paths, !noexit);
+ w.runScript(script, outdir, paths, arg, !noexit);
}
return a.exec();
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 3d02459..39f95a4 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -860,14 +860,14 @@ void MainWindow::openFileManager()
#endif
}
-void MainWindow::runScript(const QString &script, const QString &outdir, const QStringList &paths, bool exit)
+void MainWindow::runScript(const QString &script, const QString &outdir, const QStringList &paths, const QString &arg, bool exit)
{
BatchProcessing *batchProcessing = new BatchProcessing(m_database, this);
batchProcessing->setOutputDir(outdir);
batchProcessing->setPaths(paths);
if(exit)batchProcessing->hide();
- QTimer::singleShot(500, [batchProcessing, script, exit](){
- batchProcessing->runScript(script, exit);
+ QTimer::singleShot(500, [batchProcessing, script, exit, arg](){
+ batchProcessing->runScript(script, arg, exit);
batchProcessing->exec();
delete batchProcessing;
if(exit)QCoreApplication::exit();
diff --git a/src/mainwindow.h b/src/mainwindow.h
index 2855171..88922b5 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -71,7 +71,7 @@ public slots:
void exportCSV();
void checkNewVersion();
void openFileManager();
- void runScript(const QString &script, const QString &outdir, const QStringList &paths, bool exit);
+ void runScript(const QString &script, const QString &outdir, const QStringList &paths, const QString &arg, bool exit);
};
#endif // MAINWINDOW_H
diff --git a/src/scriptengine.cpp b/src/scriptengine.cpp
index 17acfb1..4421247 100644
--- a/src/scriptengine.cpp
+++ b/src/scriptengine.cpp
@@ -38,9 +38,11 @@ ScriptEngine::ScriptEngine(Database *database, BatchProcessing *parent)
#endif // PLATESOLVER
}
-void ScriptEngine::setParams(const QString &scriptPath, const QList> &paths, const QString &outputDir)
+void ScriptEngine::setParams(const QString &scriptPath, const QList> &paths, const QString &outputDir, const QString &arg)
{
_scriptPath = scriptPath;
+ if(!arg.isNull())
+ _jsEngine->globalObject().setProperty("scriptarg", arg);
setPaths(paths);
_outputDir = outputDir + "/";
}
@@ -965,9 +967,9 @@ ScriptEngineThread::~ScriptEngineThread()
if(_engine)_engine->interrupt();
}
-void ScriptEngineThread::setParams(const QString &scriptPath, const QList> &paths, const QString &outputDir)
+void ScriptEngineThread::setParams(const QString &scriptPath, const QList> &paths, const QString &outputDir, const QString &arg)
{
- _engine->setParams(scriptPath, paths, outputDir);
+ _engine->setParams(scriptPath, paths, outputDir, arg);
}
void ScriptEngineThread::start()
diff --git a/src/scriptengine.h b/src/scriptengine.h
index 7eb03dd..b4ad251 100644
--- a/src/scriptengine.h
+++ b/src/scriptengine.h
@@ -33,7 +33,7 @@ class ScriptEngine : public QObject
Solver *_solver = nullptr;
public:
explicit ScriptEngine(Database *database, BatchProcessing *parent = nullptr);
- void setParams(const QString &scriptPath, const QList> &paths, const QString &outputDir);
+ void setParams(const QString &scriptPath, const QList> &paths, const QString &outputDir, const QString &arg);
void reportError(const QString &message);
const QString& outputDir() const;
void interrupt();
@@ -82,7 +82,7 @@ class ScriptEngineThread : public QObject
public:
ScriptEngineThread(Database *database, BatchProcessing *parent = nullptr);
~ScriptEngineThread();
- void setParams(const QString &scriptPath, const QList> &paths, const QString &outputDir);
+ void setParams(const QString &scriptPath, const QList> &paths, const QString &outputDir, const QString &arg);
void start();
void interrupt();
signals: