iMacros / Select random photo from PC

2019-09-05 19:58发布

问题:

I need to make iMacros to automatically choose random photo from a folder on my PC. How do I arrange it? This is the line from iMacros for adding some file manually:

TAG POS=1 TYPE=INPUT:FILE FORM=ID:insta-add-image-form-all ATTR=ID:edit-insta-image-upload CONTENT=/path/to/the/specific/file

Thanks.

For Shugar

Here’s how my script looks like:

asd.iim

VERSION BUILD=8920312 RECORDER=FX
TAB T=1
URL GOTO=https://onlypult.com/dashboard
TAG POS=1 TYPE=A ATTR=TXT:Calendar
TAG POS=1 TYPE=A ATTR=TXT:+
TAG POS=1 TYPE=INPUT:FILE FORM=ID:insta-add-image-form-all ATTR=ID:edit-insta-image-upload CONTENT={{rndFilePath}}
TAG POS=1 TYPE=BUTTON FORM=ID:insta-add-image-form-all ATTR=ID:edit-nextsubmit--2
TAG POS=1 TYPE=BUTTON FORM=ID:insta-add-image-form-all ATTR=ID:edit-nextsubmit--3
TAG POS=1 TYPE=BUTTON FORM=ID:insta-add-image-form-all ATTR=ID:edit-saveimaage

asd.js

SET folderPath /path/to/folder/
SET rndFilePath EVAL("var arrFile = []; var file = Components.classes['@mozilla.org/file/local;1'].createInstance(Components.interfaces.nsILocalFile); file.initWithPath('{{folderPath}}'); var filesEnum = file.directoryEntries; while (filesEnum.hasMoreElements()) {arrFile.push(filesEnum.getNext().QueryInterface(Components.interfaces.nsILocalFile).path);} arrFile[Math.floor(Math.random()*(arrFile.length))];")
PROMPT {{rndFilePath}}

Both files are in folder /iMacros/Macros. When it comes to line with CONTENT={{rndFilePath}}, nothing happens. Normally that line looks like this

TAG POS=1 TYPE=INPUT:FILE FORM=ID:insta-add-image-form-all ATTR=ID:edit-insta-image-upload CONTENT=/path/to/content.jpg

The thing is, I need to click and choose some file because there appears dropdown menu when I click on «upload from PC», I cannot just write copy-paste the path to the file. Is it possible?

回答1:

If you’re using Firefox, the code below returns the full path to a random file from the folder ‘D:\Temp\img’ (specified with the ‘folderPath’ variable).

SET folderPath D:\\\Temp\\\img
SET rndFilePath EVAL("var arrFile = []; var file = Components.classes['@mozilla.org/file/local;1'].createInstance(Components.interfaces.nsILocalFile); file.initWithPath('{{folderPath}}'); var filesEnum = file.directoryEntries; while (filesEnum.hasMoreElements()) {arrFile.push(filesEnum.getNext().QueryInterface(Components.interfaces.nsILocalFile).path);} arrFile[Math.floor(Math.random()*(arrFile.length))];")
PROMPT {{rndFilePath}}


标签: imacros