• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Stop Packaging based on file path [JS]

Community Expert ,
Dec 06, 2017 Dec 06, 2017

Copy link to clipboard

Copied

In a previous post I asked about getting the file path of the final package, which was very helpful.

Get Packaged Folder Path [JS]

Now I'm looking to do something a bit different. I want to check the desired file path of the package before the package is made so I can cancel the packaging and display a message. So the user choose File > Package, selects a folder and proceeds to package, but if it's a specific path I want to cancel the package before it starts. Using the info in the other post I can get the file path, but that happens after the package, not before. Is what I want to do possible, and if so can you point me in the direction?

As long as I can get the path I'll know how to parse it to figure out if it's the one I want, I just don't know how to do this before the packaging starts and how to cancel the packaging.

Thanks in advance.


— Adobe Certified Expert & Instructor at Noble Desktop | Web Developer, Designer, InDesign Scriptor
TOPICS
Scripting

Views

705

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Dec 07, 2017 Dec 07, 2017

Correct Laubender​, I need to look at the path of the packaged file, not the current file. But the answers here sparked an idea that I think is working (although I have to test it more to make sure).

In the other thread I linked to, there was an listenAfterInvokePackage function. I adapted that to listenBeforeInvokePackage. Then the trickier part was... inside that function I created a temporary beforeSaveACopy eventListener so I could grab the file path. After I did my testing on the file path

...

Votes

Translate

Translate
Community Expert ,
Dec 06, 2017 Dec 06, 2017

Copy link to clipboard

Copied

Hi Dan,

I did not test event "beforeSaveACopy".
Maybe you could exploit that, if the event returns a valid file object for property fullName.
If not, I see no chance for now…

Regards,
Uwe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 07, 2017 Dec 07, 2017

Copy link to clipboard

Copied

How about:

app.menuActions.itemByID (39938).addEventListener ("beforeInvoke", beforePackage);

function beforePackage(evt) {

    alert(app.activeDocument.fullName);

}

if document.fullName doesn't match your requirements:

evt.preventDefault()

Bob

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 07, 2017 Dec 07, 2017

Copy link to clipboard

Copied

Hi Bob,

I did not test your code, but I don't think, that this is working the way Dan would like.


The alert is showing the fullName of the document you want to package.
What is needed is the file path the user decides to store the package.

And finally prevent packaging if it is the wrong place.

Regards,
Uwe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 07, 2017 Dec 07, 2017

Copy link to clipboard

Copied

Correct Laubender​, I need to look at the path of the packaged file, not the current file. But the answers here sparked an idea that I think is working (although I have to test it more to make sure).

In the other thread I linked to, there was an listenAfterInvokePackage function. I adapted that to listenBeforeInvokePackage. Then the trickier part was... inside that function I created a temporary beforeSaveACopy eventListener so I could grab the file path. After I did my testing on the file path I had to remove that temporary beforeSaveACopy eventListener so it wouldn't stick around and be a problem if someone later did an actual Save a Copy!

Even though Bob's example wasn't exactly what I needed, the .preventDefault() did let me cancel the packaging.


— Adobe Certified Expert & Instructor at Noble Desktop | Web Developer, Designer, InDesign Scriptor

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 08, 2017 Dec 08, 2017

Copy link to clipboard

Copied

My bad. I wasn't focused on the file path, just whether this menuEvent could be listened for.

So now I'm wondering if there is a way to export the Package entirely under script control, where you get to dictate the file path or limit it to the "correct" choices. If so, the event-listener could ALWAYS preventDefault() and then take control of the process. Maybe that would remove the complication with the SaveACopy listener. Instead of listening for an event, which might be triggered a number of ways, you're listening only to a particular MenuAction.

Of course, this would mean that your script would be in charge of all uses of Package... If there are times when a user needs to use some other filepath, you might want to provide an escape route.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 08, 2017 Dec 08, 2017

Copy link to clipboard

Copied

LATEST

Bob, that certainly is one route you could take, but I didn't want to recreate the entire packaging functionality with scripting. So luckily after further testing I can confirm the technique I mentioned above works. Thanks for the help everyone!


— Adobe Certified Expert & Instructor at Noble Desktop | Web Developer, Designer, InDesign Scriptor

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines